-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Compiler error unhelpful #17224
Comments
I have a fix for this, that uses another method, but I'm still quite curious why this gives an error. |
@SimonMeskens Here's a simpler example that demonstrates the issue: function foo<T extends "Test">() {
let x: T = "Test"; // Error, "Test" is not assignable to T
} Given a type parameter T with a constraint C, T is known to be a subtype of C. Therefore, T is assignable to C, but not the other way around. However, in cases where C is a unit type, we effectively know that T and C are idential (because the only possible argument for T is C), but we don't currently take that into account. |
I don't think that's the error here actually, as this code works: type HKTof<URIHKTof extends HKTS, A> = URI2HKT<A>[URIHKTof]; Which does exactly the same constrained parameter indexing the exact same class. |
No, I think it boils down to what I said above. This simplification also fails: type HKTof<URIHKTof extends HKTS, A> = HKTTest<URIHKTof, A, Test<A>>; Here the third type argument to |
Interesting, thanks, I think I understand a little better now. The type system is so powerful, it's hard to reason about these complex structures sometimes. It almost turns into write-only code. Luckily we can bury code like this in libraries, so they don't face the user. |
TypeScript Version: 2.4.1
Code
I think this code should typecheck, but it doesn't. If it's not a bug in the code, the compiler error is clearly wrong, so either this is a bug with the typechecker or the error it gives is wrong.
This specific code is all that stops higher kinded types from being completely typesafe in TypeScript, so it'd be a really useful feature.
The text was updated successfully, but these errors were encountered: