Skip to content

Elaborate into arrow return expressions and array types - #27040

Merged
Wesley Wigham (weswigham) merged 7 commits into
microsoft:masterfrom
weswigham:elaborate-into-arrows
Sep 17, 2018
Merged

Wesley Wigham (weswigham) merged 7 commits into
microsoft:masterfrom
weswigham:elaborate-into-arrows

Conversation

@weswigham

Copy link
Copy Markdown
Member

When either seems viable.

Fixes the easier parts of #27030

@weswigham

Copy link
Copy Markdown
Member Author

Comment thread src/compiler/checker.ts
return false;
}
// Or functions with annotated parameter types
if (some(node.parameters, ts.hasType)) {

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

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 Ryan Cavanaugh (@RyanCavanaugh) or Brian Terlson (@bterlson) to weigh in as well.

Comment thread src/compiler/checker.ts Outdated
}

function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined): Type {
function checkArrayLiteral(node: ArrayLiteralExpression, checkMode: CheckMode | undefined, forceTuple?: boolean): Type {

Copy link
Copy Markdown
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. No newline at end of file

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Wesley Wigham (weswigham) merged commit f6321bf into microsoft:master Sep 17, 2018
@weswigham
Wesley Wigham (weswigham) deleted the elaborate-into-arrows branch September 17, 2018 23:45
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants