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

Infering by nested kind #48383

Closed
jozefchutka opened this issue Mar 23, 2022 · 2 comments
Closed

Infering by nested kind #48383

jozefchutka opened this issue Mar 23, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@jozefchutka
Copy link

Bug Report

πŸ”Ž Search Terms

infer, kind, nested

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type MyObject =  {
	readonly kind:{kind:"a";};
  readonly a:string;
} | {
	readonly kind:{kind:"b";};
}

const create = ():MyObject => ({a:"", kind:{kind:"a"}});
const media = create();
media.kind.kind === "a" && media.a; // Property 'a' does not exist on type 'MyObject'.

πŸ™ Actual behavior

Compiler throws error on the last

Property 'a' does not exist on type 'MyObject'.
  Property 'a' does not exist on type '{ readonly kind: { kind: "b"; }; }'.

πŸ™‚ Expected behavior

By type definition, compiler has enough information to resolve that property a does exist on my object b/c there is no other option for media.kind.kind === "a"

@fatcerberus
Copy link

Duplicate of #18758

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 23, 2022
@typescript-bot
Copy link
Collaborator

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

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