-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Better array and object inferred types with checkJs and strict / noImplicitAny #16137
Comments
in a .js file there are few places where The assumption here is js file checking with checkJs is a loose version of checking; our mental model of this feature is that there is a spectrum of strictness, where: Just for curiosity; have you considered moving your files to .ts? |
I use Angular so I'm used to TypeScript and I love it, but I'm very interested with the new After more investigation, array behavior is quite OK : you can mix values of different types on array creation, but once the type is inferred, It's OK for objects with I'll post another message in the other topic you mention. |
May I ask you why you did you decide to close this issue? Inferred type of an object still has It would be so much helpful if TypeScript raised errors when it encounters an undefined property, just like it happens with const sample = {
DEFINED_PROPERTY: 'FOO'
};
sample.UNDEFINED_PROPERTY.indexOf('BAR'); |
TypeScript Version: 2.3.3
Code
In a JavaScript file (not TypeScript), with the new
checkJs
option enabled :Actual behavior:
In normal mode, no errors are raised, and it's OK as it's the normal JS behavior.
In
strict
ornoImplicitAny
mode, no errors are raised either, despite the fact that the inferred type foruser
is :{ [x: string]: any; name: string; age: number; }
. For the array, it's(string | number)[]
but in the purpose of error checking it's likeany[]
.Expected behavior:
In
strict
ornoImplicitAny
mode, errors should be raised.It seems important to me for 2 reasons :
@type
or@param
JSDoc comments are not supported by TS yet (see Intellisense for object properties defined in multi-line JSDoc comments #11597).The text was updated successfully, but these errors were encountered: