mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
37 lines
1.3 KiB
Plaintext
37 lines
1.3 KiB
Plaintext
genericWithNoConstraintComparableWithCurlyCurly.ts(23,5): error TS2352: Conversion of type '{}' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
|
'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.
|
|
|
|
|
|
==== genericWithNoConstraintComparableWithCurlyCurly.ts (1 errors) ====
|
|
function foo<T>() {
|
|
let x = {};
|
|
x as T;
|
|
}
|
|
|
|
function bar<T extends unknown>() {
|
|
let x = {};
|
|
x as T;
|
|
}
|
|
|
|
function baz<T extends {}>() {
|
|
let x = {};
|
|
x as T;
|
|
}
|
|
|
|
function bat<T extends object>() {
|
|
let x = {};
|
|
x as T;
|
|
}
|
|
|
|
function no<T extends null | undefined>() {
|
|
let x = {};
|
|
x as T; // should error
|
|
~~~~~~
|
|
!!! error TS2352: Conversion of type '{}' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
|
|
!!! error TS2352: 'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.
|
|
}
|
|
|
|
function yes<T extends object | null | undefined>() {
|
|
let x = {};
|
|
x as T;
|
|
} |