Skip to content
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

Type refinement on properties no longer refines the whole structure #58197

Closed
sukovanej opened this issue Apr 15, 2024 · 3 comments
Closed

Type refinement on properties no longer refines the whole structure #58197

sukovanej opened this issue Apr 15, 2024 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@sukovanej
Copy link

πŸ”Ž Search Terms

type guard, type refinement, typescript 5.4.3

πŸ•— Version & Regression Information

  • This changed between versions 5.4.2 and 5.4.3

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBA6lC8UDeUBOECGATA9gOwBsQpRIAuKAcg0oG4oAjCvAVwFsGJUoBfWgKFLQAWgmRpMuQsSEVKDOlADGFAM7BUASzwBzXgKFQAGmLgAfKMIH8sEJQQzpl+dVAAeFI9aUvgUTaoAgmIAFLJUNFAW8pQAlBSGARGUCAB8JODQ8NnJ1poAZlAhAYEhbgB0QrGxyPxQ7uUM9AD0ze5QABYYqlAYGZDG-njqklA4hTD8PEA

πŸ’» Code

type W = { readonly type: 'a'; b: number };
type Z = { readonly type: 'b'; c: string };
type X = W | Z;

declare const x: X;

const isA = (type: 'a' | 'b'): type is 'a' => type === 'a';

if (isA(x.type)) {
  x.b; // x has a type X instead of W
}

πŸ™ Actual behavior

the x has the wider type X

πŸ™‚ Expected behavior

x has the concrete type W

Additional information about the issue

No response

@Andarist
Copy link
Contributor

Likely this was depending on the PR that got reverted (see #57750 )

@RyanCavanaugh
Copy link
Member

-> #45770

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 15, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants