We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
generic narrow type guard object index
v4.2.3
Playground link with relevant code
type FO = 'f' | 'o' type Foo<Type extends FO = FO> = { [T in Type]: { type: T, data: Record<T, true>, } }[Type] const foo = {} as Foo if (foo.type === 'f') foo.data.f // all good, narrows the type type Bar<Type extends FO = FO> = { [T in Type]: { foo: Foo<T> } & { f: { bar: Record<T, true> }, o: unknown, }[T] }[Type] const bar = {} as Bar if (bar.foo.type === 'f') bar.bar // broke
Property 'bar' does not exist on type 'Bar'
bar.bar identified as Record<T, true> because it's in the same indexed property as bar.foo.type for T that is equals to f
bar.bar
Record<T, true>
bar.foo.type
T
f
The text was updated successfully, but these errors were encountered:
See #18758
Sorry, something went wrong.
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
Bug Report
π Search Terms
generic narrow type guard object index
π Version & Regression Information
v4.2.3
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
π Expected behavior
bar.bar
identified asRecord<T, true>
because it's in the same indexed property asbar.foo.type
forT
that is equals tof
The text was updated successfully, but these errors were encountered: