New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved TypeScript ergonomics #12
Comments
I've got a plugin for boolean types, want that in core @thepassle ? |
What does the plugin do exactly? Assign the type of I think we could add some type inference behavior for fields, (and variables?), but we'd need to make sure to keep the correct 'priority' of type systems. Currently JSDoc will overrule TS types, so the priority should probably be (from least prio to highest prio):
|
Since op i updated the plugin to handle
if (isBoolean(node))
memberDoc.type = { text: 'boolean' };
else if (isAsConst(node.initializer, api))
memberDoc.type = { text: node.initializer.expression.getText() };
else if (api.isStringLiteral(node.initializer))
memberDoc.type = { text: 'string' };
else if (api.isNumericLiteral(node.initializer))
memberDoc.type = { text: 'number' }; |
I'll open a draft PR and we can go over it there 🙂 |
I think we should make a new handler for this, something like fieldTemplate = handleTypeInference(fieldDoc, node); That way we can easily add it for variables as well |
type inference was added, ill close this for now |
This issue tracks some nice-to-have enhancements for type detection.
The analyzer does great picking up on explicitly typed members:
Here,
B
x
field will be correctly typed asX<A>
bool
field will be typed asboolean
However, it would be nice if for the following code:
Would give:
B extends Constructor<{ b: B }>
x
field asX<A>
(even without an explicit typing)bool
field asboolean
(even without an explicit typing)I'm guessing that the TypeScript API has the chops to infer those things, given a
SourceFile
AST, but I haven't looked into it just yet.The text was updated successfully, but these errors were encountered: