Skip to content

Correctly check types in type assertions #9170

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 8 commits into from
Jun 15, 2016

Conversation

DanielRosenwasser
Copy link
Member

Fixes #9103.

@@ -5027,6 +5027,7 @@ namespace ts {
function getTypeFromTupleTypeNode(node: TupleTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
checkTupleType(node);
Copy link
Member

@ahejlsberg ahejlsberg Jun 14, 2016

Choose a reason for hiding this comment

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

That's not the right fix. This function is simply for materializing the type, it isn't for the actual checking. The real problem is that checkAssertion never calls checkSourceElement on node.type. You can prove that to yourself by observing that this doesn't generate an error either:

var x = <{ a: number, a: number }>undefined;  // No duplicate identifier error

So, remove the line above and instead put a call to checkSourceElement(node.type) in checkAssertion.

@DanielRosenwasser DanielRosenwasser changed the title Disallow empty tuples types in type assertions (and elsewhere) Disallow invalid types in type assertions Jun 15, 2016
@DanielRosenwasser DanielRosenwasser changed the title Disallow invalid types in type assertions Correctly check types in type assertions Jun 15, 2016
@DanielRosenwasser
Copy link
Member Author

Fixed.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 15, 2016

👍

var y = <(a : string = "") => any>(undefined)
Copy link
Member

Choose a reason for hiding this comment

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

😆

@RyanCavanaugh
Copy link
Member

👍

@DanielRosenwasser DanielRosenwasser merged commit 9a2cf11 into master Jun 15, 2016
@DanielRosenwasser DanielRosenwasser deleted the emptyTupleAssertions branch June 15, 2016 19:35
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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.

5 participants