Preact: Use typescript's --checkJS to validate preact doc comments

Created on 28 Apr 2017  路  6Comments  路  Source: preactjs/preact

  1. Community doesn't have to maintain a separate .d.ts, this could be generated from code.
  2. Preact already uses jsdoc, and --checkJS can actually validate the typings specified in jsdoc.
  3. Anyone making changes to preactjs will get excellent code completion and intellisense if they are using a typescript plugin in vscode, sublime, atom, vim e.t.c

All 6 comments

Wow, had no idea it could do that. Definitely liking this idea.

This is new in the TypeScript 2.3 release.

Community doesn't have to maintain a separate .d.ts, this could be generated from code.

I'm not sure that's possible. Does TypeScript's JSDoc support allow defining types in one module and then re-using them from another module? From my limited testing this appears not to be the case. On that basis, shared interfaces would still need to be defined in the .d.ts file but could then be referenced by JSDoc comments.

Update: there's a feature in the works, apparently nearing completion:

https://github.com/Microsoft/TypeScript/issues/7546

https://github.com/Microsoft/TypeScript/pull/15911

+1 on the idea!
btw, how about moving preact code base to typescript?
it can be done gradually (like 10% -> 30% -> ...), IDEs starts to help devs with auto-suggestions & refactoring goodies, etc.

@devmacmari you can read about it here https://github.com/developit/preact/issues/639#issuecomment-302917848

We discussed moving to TS a few times internally and some of us even attempted to do that on our own. Two of us are quite the fans of TS, but we both came to the realization that it doesn't work well with our code. We employ some tricks to determine the type of a variable which are failing in TS (checked with 3.3.3333).

Here is a simple example that breaks:

// Pseudo example, not real code
function isType(arg: object | any[]) {
    // Will break here
    if (arg.pop) return "array";
    return "object"
}

As much as I'd love to add this (or enable checkJs) we are blocked by this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthewmueller picture matthewmueller  路  3Comments

paulkatich picture paulkatich  路  3Comments

jescalan picture jescalan  路  3Comments

marcosguti picture marcosguti  路  3Comments

simonjoom picture simonjoom  路  3Comments