Skip to content

Add an additional test for favoring the asserted type in type predicate narrowing #50065

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 2 commits into from
Jul 29, 2022

Conversation

Andarist
Copy link
Contributor

I've noticed that the #50044 didn't introduce a new test related to the issue that it closed and I've figured out that it might be nice to add it

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 27, 2022
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Comment on lines 8 to 22
declare const obj1: {};
obj1; // {}
if (isObject(obj1)) {
obj1; // Record<string, unknown>
obj1['attr'];
}
obj1; // Record<string, unknown>

declare const obj2: {} | undefined;
obj2; // {} | undefined
if (isObject(obj2)) {
obj2; // Record<string, unknown>
obj2['attr'];
}
obj2; // Record<string, unknown> | undefined
Copy link
Member

Choose a reason for hiding this comment

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

I know it's unfair to ask this of you since there were no tests, but:

  • I would remove the comments - the type baselines and errors will indicate these better and not need to be updated.
  • I would also add test cases for a type predicate like value is {} acting on Record<string, unknown> and Record<string, unknown> | undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem - I've added the requested test cases and removed those comments (I've originally kept them as they are pretty popular in your test suite)

Copy link
Member

@DanielRosenwasser DanielRosenwasser Jul 29, 2022

Choose a reason for hiding this comment

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

I've originally kept them as they are pretty popular in your test suite

Yeah, I am not a fan 😅

They fall out of date with the baselines so it never made sense.

@DanielRosenwasser DanielRosenwasser merged commit 5374fd9 into microsoft:main Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants