6aeb8c12cc
* Create separate types for equivalent aliased unions * Accept new baselines * Preserve original types for union types * Accept new baselines * Preserve intersection origin for union types * Accept new baselines * Accept new baselines * Preserve aliases during relationship checks * Accept new baselines * Preserve aliases for intersection and indexed access types * Accept new baselines * Compute intersection-of-unions cross product without recursion * Accept new baselines * Use denormalized type objects for origin / support 'keyof' origins * Accept new baselines * Fix fourslash test * Recursively extract named union types * Accept new baselines * Map on union origin in mapType to better preserve aliases and origins * Remove redundant call * Accept new baselines * Revert back to declared type when branches produce equivalent union * Accept new baselines * Don't include denormal origin types in regular type statistics * Fix issue with unions not being marked primitive-only * Allow new alias to be associated with type alias instantiation * Accept new baselines * Revert "Accept new baselines" This reverts commit4507270cc1
. * Revert "Allow new alias to be associated with type alias instantiation" This reverts commit2c2d06dfe1
.
95 lines
2.5 KiB
Plaintext
95 lines
2.5 KiB
Plaintext
=== tests/cases/conformance/types/intersection/intersectionWithUnionConstraint.ts ===
|
|
function f1<T extends string | number, U extends string | number>(x: T & U) {
|
|
>f1 : <T extends string | number, U extends string | number>(x: T & U) => void
|
|
>x : T & U
|
|
|
|
// Combined constraint of 'T & U' is 'string | number'
|
|
let y: string | number = x;
|
|
>y : string | number
|
|
>x : T & U
|
|
}
|
|
|
|
function f2<T extends string | number | undefined, U extends string | null | undefined>(x: T & U) {
|
|
>f2 : <T extends string | number | undefined, U extends string | null | undefined>(x: T & U) => void
|
|
>null : null
|
|
>x : T & U
|
|
|
|
let y1: string | number = x; // Error
|
|
>y1 : string | number
|
|
>x : T & U
|
|
|
|
let y2: string | null = x; // Error
|
|
>y2 : string | null
|
|
>null : null
|
|
>x : T & U
|
|
|
|
let y3: string | undefined = x;
|
|
>y3 : string | undefined
|
|
>x : T & U
|
|
|
|
let y4: number | null = x; // Error
|
|
>y4 : number | null
|
|
>null : null
|
|
>x : T & U
|
|
|
|
let y5: number | undefined = x; // Error
|
|
>y5 : number | undefined
|
|
>x : T & U
|
|
|
|
let y6: null | undefined = x; // Error
|
|
>y6 : null | undefined
|
|
>null : null
|
|
>x : T & U
|
|
}
|
|
|
|
type T1 = (string | number | undefined) & (string | null | undefined); // string | undefined
|
|
>T1 : string | undefined
|
|
>null : null
|
|
|
|
function f3<T extends string | number | undefined>(x: T & (number | object | undefined)) {
|
|
>f3 : <T extends string | number | undefined>(x: T & (number | object | undefined)) => void
|
|
>x : T & (number | object | undefined)
|
|
|
|
const y: number | undefined = x;
|
|
>y : number | undefined
|
|
>x : T & (number | object | undefined)
|
|
}
|
|
|
|
function f4<T extends string | number>(x: T & (number | object)) {
|
|
>f4 : <T extends string | number>(x: T & (number | object)) => void
|
|
>x : T & (number | object)
|
|
|
|
const y: number = x;
|
|
>y : number
|
|
>x : T & (number | object)
|
|
}
|
|
|
|
function f5<T, U extends keyof T>(x: keyof T & U) {
|
|
>f5 : <T, U extends keyof T>(x: keyof T & U) => void
|
|
>x : keyof T & U
|
|
|
|
let y: keyof any = x;
|
|
>y : string | number | symbol
|
|
>x : keyof T & U
|
|
}
|
|
|
|
// Repro from #23648
|
|
|
|
type Example<T, U> = { [K in keyof T]: K extends keyof U ? UnexpectedError<K> : NoErrorHere<K> }
|
|
>Example : Example<T, U>
|
|
|
|
type UnexpectedError<T extends PropertyKey> = T
|
|
>UnexpectedError : T
|
|
|
|
type NoErrorHere<T extends PropertyKey> = T
|
|
>NoErrorHere : T
|
|
|
|
// Repro from #30331
|
|
|
|
type a<T> = T extends Array<infer U> ? U : never;
|
|
>a : a<T>
|
|
|
|
type b<T> = { [K in a<T> & keyof T ]: 42 };
|
|
>b : b<T>
|
|
|