Type Safety for Superfine Source Code Through JSDoc Types.
See original GitHub issueI made a fork of Superfine with full type safety for Superfine source code using only JSDoc: https://github.com/rbiggs/superfine/tree/JSDoc This gives you full intellisense, code completion, live type checking, etc. in the source code as JavaScript. Just set your user preferences in VSCode to:
"javascript.implicitProjectConfig.checkJs": true
Then examine the source code in VSCode. This lets you write plain ole JavaScript with all the benefits of typed TypeScript.
Because JSDoc comments are valid JavaScript comments, they do not affect the final output of the source code during build time. The JSDoc comments get removed during minification. Using types in the source code does require escaping expando properties with [""]
, but these also get removed during minification.
This provides custom types for VNode, etc., and type casting to resolve static type checking’s inability to force type casting that occurs during runtime in the browser. The cast item requires extra parens around it to signal that it is being cast, but these get removed during minification as well.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:14 (7 by maintainers)
Basically, the same reason one would write Superfine in TypeScript–type safety for the entire code base. With that in place, incorrect use of types in the source code will show up immediately. Besides, some people, myself particularly, like to import source files instead of distribution files to work with. I let my build pipe line handle the bundling and minification. An external
d.ts
file only describes what the external public interface is, but doesn’t ensure that anything internal is correctly typed.In #134 you mentioned a possible rewrite in TypeScript. I’m assuming for type correctness. This gives you the same thing while keeping it JavaScript. No need for a build step to convert it to JavaScript. It’s already the JavaScript you want, but with types.
Thank you, both! JSDoc looks promising, but I’m seriously considering to rewrite Superfine in TS.