News for hackers. Stuff that matters.
Re:A 'CSS reset' for TypeScript, improving types for common ... by schwartzworld on Friday March 03, 2023 @09:56AM (#35010389)
> Knowing that what is shipped is what you wrote, not what some transpiler spat out, might have some value.

There aren't that many TS features that actually require transpiling unless you want to write bleeding edge JS, and that's still a factor without typescript.

> No build step is an appealing feature for some.

ts-node exists

My question is how do you reuse and test the JS doc signatures? Can I export comments? Will my tests fail if the types mismatch?

Re:A 'CSS reset' for TypeScript, improving types for common ... by ravenstine on Friday March 03, 2023 @10:31AM (#35010874)
I don't want to use Typescript for everything.

A recent example is a Chrome extension I wrote for the sake of proving out a feature.

Totally not interested in setting up a build system, dealing with dependencies, type safety, and so forth. I just want to write code and immediately see it run. Having JSDoc is nice to document more than just types, but type hints can be helpful.

> My question is how do you reuse and test the JS doc signatures? Can I export comments? Will my tests fail if the types mismatch?

You can import types now, at least with VS Code.

``` /* * @typedef {import('./types.js').MyType} MyType */ ```

Haven't found myself using it, though.

Re:A 'CSS reset' for TypeScript, improving types for common ... by c-hendricks on Friday March 03, 2023 @02:22PM (#35013854)
> You can import types now

When using TypeScript to avoid using TypeScript, yeah. It's not valid JSDoc: https://github.com/jsdoc/jsdoc/issues/1645

Re:A 'CSS reset' for TypeScript, improving types for common ... by kristiandupont on Friday March 03, 2023 @10:09AM (#35010563)
I'm working on a JS project for a client. I can't modify the deployment procedure so I can't add a build step and ts-node is no help because it's frontend.

JSDoc comments can be checked with TSC and I get squiggly lines in VSCode. It's a major step in the right direction. Obviously tests work the same they always did, there is no runtime type checking just as there isn't in TS.

Re:A 'CSS reset' for TypeScript, improving types for common ... by schwartzworld on Friday March 03, 2023 @10:39AM (#35010991)
You could build it before you check the code in.
Re:A 'CSS reset' for TypeScript, improving types for common ... by kristiandupont on Friday March 03, 2023 @11:34AM (#35011750)
I guess, but that seems at least as tedious as maintaining JSDoc comments to me.
Re:A 'CSS reset' for TypeScript, improving types for common ... by tytho on Friday March 03, 2023 @10:22AM (#35010776)
You can still use `tsc` to validate the jsdoc types. It will spit out errors when types don’t match.

You can use `tsc` to export the types defined in jsdoc and other projects that import your module will get all the intellisense and type checking as if it had been written in TypeScript.