on-internet
← Community

Typescript doesn't infer correct type with Generic extending string union type?

Stack Overflow ·

type Test = 'a' | 'b' | 'c'; function foo<T extends Test>(arg: T) { if (arg === 'a') { console.log(arg); } } like this.. I expect arg inferred 'a' in if block. but ts infer as just T. why this situation? I think that extends keyword has something...

Comments

Sign in or sign up to comment and upvote.

No comments yet.