* Add unmeasurable variance kind for marking types whose variance result is unreliable * Remove now-unneeded nongeneric checks * Add rule allowing `Readonly<any>` to be `any` instead of `{readonly [index: string]: any}` * All Unmeasurable variances to still shortcut structural comparisons in some cases * Separate unmeasurable from unreliable to reduce the impact of this change, for now * Fix lint * Remove Readonly<any> -> any callout * Add fix for circularity error triggered by deep signature return type comparisons with `this` types
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
// TODO: FIXME: All the below cases labeled `no error` _should be an error_, and are only prevented from so being
|
|
// by incorrect variance-based relationships
|
|
// Ref: https://github.com/Microsoft/TypeScript/issues/29698
|
|
|
|
type Record2<K extends keyof any, T> = {
|
|
[P in K]: T;
|
|
};
|
|
|
|
function defaultRecord(x: Record<'a', string>, y: Record<string, string>) {
|
|
x = y; // no error, but error expected.
|
|
}
|
|
|
|
function customRecord(x: Record2<'a', string>, y: Record2<string, string>) {
|
|
x = y; // no error, but error expected.
|
|
}
|
|
|
|
function mixed1(x: Record2<'a', string>, y: Record<string, string>) {
|
|
x = y; // error
|
|
}
|
|
|
|
function mixed2(x: Record<'a', string>, y: Record2<string, string>) {
|
|
x = y; // error
|
|
}
|
|
|
|
function defaultRecord2<T>(x: Record<'a', T>, y: Record<string, T>) {
|
|
x = y; // no error, but error expected.
|
|
}
|
|
|
|
function customRecord2<T>(x: Record2<'a', T>, y: Record2<string, T>) {
|
|
x = y; // no error, but error expected.
|
|
}
|
|
|
|
function mixed3<T>(x: Record2<'a', T>, y: Record<string, T>) {
|
|
x = y; // error
|
|
}
|
|
|
|
function mixed4<T>(x: Record<'a', T>, y: Record2<string, T>) {
|
|
x = y; // error
|
|
}
|