-
Notifications
You must be signed in to change notification settings - Fork 12.8k
identical conditional types not assignable to each other #21756
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
IMHO, if a conditional type is already resolved, compare the resolved type. If target type is an unresolved conditional type, compare the source type:
But this usage sounds weird, @tvald could you please give a concrete example where you need to assign/compare two conditional types? |
This is the particular case: // lib/es5.d.ts
declare type PromiseConstructorLike = new <T>(executor: (
resolve: T extends void ? (value?: PromiseLike<void>) => void : (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void) => void
) => PromiseLike<T>;
// lib/es2015.promise.d.ts
interface PromiseConstructor {
new <T>(executor: (
resolve: T extends void ? (value?: PromiseLike<void>) => void : (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void) => void
): Promise<T>;
} It's reasonable to expect interoperability across compatible type definitions - perhaps originating from different libraries, perhaps narrowed from more complex types. Not supporting structural comparison of conditional types feels like a significant deviation from the way the rest of the type system works. |
This is behaving as intended, but i think we should reconsider. |
I agree, two conditional types should be identical if they have the same four constituent types and the same distributivity (i.e. both are distributive or both are not). Pretty easy to fix, we already have logic in place to intern conditional types, it just needs a bit of tweaking. |
Identical conditional types are not assignable to each other.
TypeScript Version: 2.8.0-dev.20180208
Code
Expected behavior:
no errors
Actual behavior:
The text was updated successfully, but these errors were encountered: