Bug Report
🔎 Search Terms
union type, type predicate
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Common Bugs That Aren't Bugs"
⏯ Playground Link
Playground link with relevant code
💻 Code
typeFoo={kind: 'foo'}interfaceBar<T=Any>{kind: 'bar',value: T}typeBaz={kind: 'baz'}typeAny=Foo|Bar|BazfunctionisFoobar(value: unknown): value is Foo|Bar<Foo>{returntypeofvalue==='object'&&((valueasany)?.kind==='foo'||(valueasany)?.kind==='bar')}letvalue={kind: 'baz'}asAnyif(isFoobar(value)){leta=value.kind==='foo'
? value.kind
: value.value.kind}🙁 Actual behavior & 🙂 Expected behavior
isFoobar narrows the type to only Foo but should narrow it to the specified Foo | Bar<Foo>. It seems to be related to the combination of the generic parameter and the circularity because I can not find a way to simplify it further.
Bug Report
🔎 Search Terms
union type, type predicate
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior & 🙂 Expected behavior
isFoobarnarrows the type to onlyFoobut should narrow it to the specifiedFoo | Bar<Foo>. It seems to be related to the combination of the generic parameter and the circularity because I can not find a way to simplify it further.