-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Build: add type check using typescript --checkJs #2267
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
Conversation
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These fixes are fine, but is there some way we could use CI to ensure they stay correct? otherwise i'm not sure they're adding value.
|
This errors are found by typescript's |
|
Let's add an |
b189e12 to
084c678
Compare
084c678 to
d344dca
Compare
| /* Strict Type-Checking Options */ | ||
| // "strict": true, /* Enable all strict type-checking options. */ | ||
| // "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
| // "strictNullChecks": true, /* Enable strict null checks. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flag strictNullChecks is left unenabled because there is about 20 places where I need to either use @ts-ignore or write very awkward codes.
|
It might make sense to add eslint-plugin-jsdoc. The errors it catches includes: 1. Missing or superfluous jsdoc param. 2. Unmatched Jsdoc param name and actual name. 3. Enforce presence of types annotation. |
lib/util/linkComponents.js
Outdated
| */ | ||
| 'use strict'; | ||
|
|
||
| /** @type {any[]}} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string[]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tsc does not accept string[]. The official type declaration requires that in a.concat(b), a and b must have the same type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when is this array concatted with something that's not also a string[]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In lines bellow it is concatted with setting.something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which should be a string[] per the schema, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By schema it could be {name: something, linkAttribute: something}[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah - then should the type be (string | { name: string, linkAttribute: string })[]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But settings.linkComponents is not validated, it could be anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's not that schema tho, the plugin won't work properly, so i think we can assume that's its type.
lib/util/propTypes.js
Outdated
| UnionTypeAnnotation: function(annotation, parentName, seen) { | ||
| const unionTypeDefinition = { | ||
| type: 'union', | ||
| /** @type {any} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets avoid any use of any :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tsc does not accept any[] and any[]|true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unknown[]? unknown[] | true? you can certainly do any of those in TS, altho maybe not in jsdoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tsc does not accept unknown[] unknown[]|true also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just in jsdoc? it certainly works in TS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unionTypeDefinition.children is at a time assigned true, so it cannot be unknown[]. unionTypeDefinition.children.length is used, so it cannot be unknown[]|true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then that implies there's a bug, or else type narrowing would have removed true prior to the .length access?
084c678 to
fce69eb
Compare
|
I somehow closed this by accident. Apologies. |
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've explicitly commented on all non-comment changes, just to be thorough.
I'd still like to avoid any use of any.
LGTM pending https://github.com/yannickcr/eslint-plugin-react/pull/2267/files#r283097857
| } | ||
| if (classComponent) { | ||
| handleClassUsage(node, classComponent); | ||
| handleClassUsage(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a harmless extra arg being passed - good to clean up. semver-patch.
| return SVGDOM_ATTRIBUTE_NAMES[name]; | ||
| } | ||
| let i; | ||
| let i = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be useless, but I assume tells tsc what the type of i is. It could also be set to 0, but -1 is clearer semantically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i is not initialized, it could potentially be undefined, that would make tsc reject DOM_PROPERTY_NAMES[i].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[undefined] on an object without that property is safely undefined, that's just the type system being overly strict :-)
| const name = classProperties.find(propertyName => { | ||
| if (propertiesToCheck[propertyName](node)) { | ||
| return propertyName; | ||
| return !!propertyName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the return value of reportNodeIncorrectlyPositioned is always used in a truthy/falsy position, this just returns true instead of "truthy"…
| } | ||
|
|
||
| return null; | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and false instead of "falsy".
|
Thanks for the thorough review! |
e6509bb to
3e7c1f6
Compare
No description provided.