-
Notifications
You must be signed in to change notification settings - Fork 12.8k
A Type Error occurs with using a generic that extends a branded intrinsic type #55040
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
Comments
What is an βinstinct typeβ? |
From context I'd say it means "primitive type"? π€·ββοΈ The issue here is probably just that generic conditional types don't consult the generic's constraints and therefore remain unresolved, as in #31096 |
Yeah, it does seem to be that issue that's occurring. Any suggestions on how I can work around it? The only solution I've come up with is to use overloads of the Also, "instinct" was a mistake by me, I meant "intrinsic". |
The conventional term is "primitive", though. In TypeScript, "intrinsic" refers to compiler-provided types that users cannot implement themselves (see #40580), and while one could make a case that all primitive types are intrinsic, not all intrinsic types are primitive. |
Ahh, good to know. I've kind of just been using the two interchangeably. |
For this substitution to be safe, the conditional type would have to be nondistributive. If you change this to type OperationIO<T extends number> = [T] extends [BrandedNumber]
? T
: number; then it indeed works as expected |
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
TypeScript reports a type error on line 35.
π Expected behavior
No error should be reported because as far I can tell, this line should be valid. Additionally, TypeScript can successfully deduce the type on line 39.
The text was updated successfully, but these errors were encountered: