Skip to content

Error on for (const x in never) - #22988

Merged
3 commits merged into
masterfrom
for_in_never
Mar 29, 2018
Merged

3 commits merged into
masterfrom
for_in_never

Conversation

@ghost

Copy link
Copy Markdown

Sequel to #22964

@weswigham Wesley Wigham (weswigham) left a comment

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.

Same comments as on the other PR. Technically it's correct to iterate over never because by definition it "has" what it need to to be iterable, but this is probably an improvement. And these error messages do not mention the type we found in place of the one we need, which would probably be useful information to have.

@ghost

Copy link
Copy Markdown
Author

How about, The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type '{0}'.?

@weswigham

Copy link
Copy Markdown
Member

Looks decent.

Comment thread src/compiler/checker.ts Outdated
if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) {
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
if (rightType === neverType || !isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) {
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter_but_here_has_type_0);

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.

you miiiiiight wanna actually pass in the type string here, so it doesn't just print undefined. 😄

@ghost
ghost merged commit a9aca81 into master Mar 29, 2018
@ghost
ghost deleted the for_in_never branch March 29, 2018 18:39
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jul 26, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

1 participant