question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type Safety for Superfine Source Code Through JSDoc Types.

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
rbiggscommented, Jul 12, 2018

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.

1reaction
jorgebucarancommented, Jul 12, 2018

Thank you, both! JSDoc looks promising, but I’m seriously considering to rewrite Superfine in TS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type-safe JavaScript code with JsDoc - Prisma
JsDoc is a great tool for documenting code and providing type-safety in your JavaScript project without any additional configuration.
Read more >
Type Safe JavaScript with JSDoc - Medium
JSDoc comments are an alternative to TypeScript and Flow for type definitions in JavaScript. In combination with VSCode you can get type ......
Read more >
Use JSDoc comments for plugin typings #798 - GitHub
... Type Safety for Superfine Source Code Through JSDoc Types. ... Good enough for type safety, intellisense, code completion and refactoring.
Read more >
Type safety in JavaScript with JSDoc and VSCode
This article aim to introduce how to make JavaScript project type safe with JSDoc, TypeScript, and VSCode. Not only make your project more ......
Read more >
JSDoc Reference - TypeScript: Documentation
You can reference types with the “@type” tag. The type can be: Primitive, like string or number . Declared in a TypeScript declaration,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found