-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Elaborate into arrow return expressions and array types #27040
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
return false; | ||
} | ||
// Or functions with annotated parameter types | ||
if (some(node.parameters, ts.hasType)) { |
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.
Why not though?
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.
Because we're only validating the return types and the error we may issue on mismatched parameter types is usually better if available.
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.
Mostly looks good to me - I'd love to brainstorm on ways to get rid of the not-so-great index signature related span, but I don't think that's a blocker.
I'd suggest you get @RyanCavanaugh or @bterlson to weigh in as well.
src/compiler/checker.ts
Outdated
@@ -16873,7 +16920,7 @@ namespace ts { | |||
(node.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>node).operatorToken.kind === SyntaxKind.EqualsToken); | |||
} | |||
|
|||
function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined): Type { | |||
function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined, forceTuple?: boolean): 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.
This is only called in two places, so make it non-optional.
!!! error TS2322: Type 'foo' is not assignable to type '{ id: number; }'. | ||
!!! error TS2322: Property 'id' is missing in type 'foo'. | ||
!!! related TS6501 /.ts/lib.es5.d.ts:1284:5: The expected type comes from this 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.
Unfortunately I think that these aren't very helpful. Is there a way to retain the topmost type and point to that?
!!! error TS2322: Type '(v: number) => number' is not assignable to type '(x: number) => string'. | ||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | ||
~ | ||
!!! error TS2322: Type 'number' is not assignable to type '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.
This one is a little bit hard to judge. It's not super clear where this number
is coming from and what it's being compared to.
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 overall signature has the same problem, since it's all inferred, IMO.
!!! error TS2345: Type '[string, number]' is not assignable to type '[string, boolean]'. | ||
!!! error TS2345: Type 'number' is not assignable to type 'boolean'. | ||
~~~~~~~~~~ | ||
!!! error TS2322: Type '(string | boolean)[]' is not assignable to type '[string, boolean]'. |
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 think this is a regression?
When either seems viable.
Fixes the easier parts of #27030