Skip to content

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

Merged
merged 7 commits into from
Sep 17, 2018

Conversation

weswigham
Copy link
Member

When either seems viable.

Fixes the easier parts of #27030

@weswigham
Copy link
Member Author

cc @DanielRosenwasser

return false;
}
// Or functions with annotated parameter types
if (some(node.parameters, ts.hasType)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not though?

Copy link
Member Author

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.

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a 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.

@@ -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 {
Copy link
Member

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.
Copy link
Member

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'.
Copy link
Member

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.

Copy link
Member Author

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]'.
Copy link
Member

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?

@weswigham weswigham merged commit f6321bf into microsoft:master Sep 17, 2018
@weswigham weswigham deleted the elaborate-into-arrows branch September 17, 2018 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants