Repository navigation
Binding element with parent type any is of type any #18955
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4151,13 +4151,13 @@ namespace ts { | |
| if (parentType === unknownType) { | ||
| return unknownType; | ||
| } | ||
| // If no type was specified or inferred for parent, or if the specified or inferred type is any, | ||
| // infer from the initializer of the binding element if one is present. Otherwise, go with the | ||
| // undefined or any type of the parent. | ||
| if (!parentType || isTypeAny(parentType)) { | ||
| if (declaration.initializer) { | ||
| return checkDeclarationInitializer(declaration); | ||
| } | ||
| // If no type was specified or inferred for parent, | ||
| // infer from the initializer of the binding element if one is present. | ||
| // Otherwise, go with the undefined type of the parent. | ||
| if (!parentType) { | ||
| return declaration.initializer ? checkDeclarationInitializer(declaration) : parentType; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's no |
||
| } | ||
| if (isTypeAny(parentType)) { | ||
| return parentType; | ||
| } | ||
|
|
||
|
|
@@ -4183,9 +4183,6 @@ namespace ts { | |
| // computed properties with non-literal names are treated as 'any' | ||
| return anyType; | ||
| } | ||
| if (declaration.initializer) { | ||
| getContextualType(declaration.initializer); | ||
| } | ||
|
|
||
| // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, | ||
| // or otherwise the type of the string index signature. | ||
|
|
||
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.
Doesn't it make sense to say "Otherwise, go with the any type of the parent"? We don't seem to do any checking for the
undefinedtype here?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 applies to the block immediately below the comment, which checks
if (!parentType). "The falsy type of the parent" would be more accurate, but isn't the intent.Any is different in that (1) you can specify any and (2) it will override the initialiser. I decided not to comment this as it seemed pretty obvious.