1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
=== tests/cases/compiler/simplifyingConditionalWithInteriorConditionalIsRelated.ts ===
// from https://github.com/microsoft/TypeScript/issues/30706
type ConditionalType<T> = T extends string ? string : number;
>ConditionalType : Symbol(ConditionalType, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 0, 0))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 1, 21))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 1, 21))
function ConditionalOrUndefined<T>(): ConditionalType<T> | undefined {
>ConditionalOrUndefined : Symbol(ConditionalOrUndefined, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 1, 61))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 3, 32))
>ConditionalType : Symbol(ConditionalType, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 0, 0))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 3, 32))
return 0 as any;
}
function JustConditional<T>(): ConditionalType<T> {
>JustConditional : Symbol(JustConditional, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 5, 1))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 7, 25))
>ConditionalType : Symbol(ConditionalType, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 0, 0))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 7, 25))
return ConditionalOrUndefined<T>()!; // shouldn't error
>ConditionalOrUndefined : Symbol(ConditionalOrUndefined, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 1, 61))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 7, 25))
}
// For comparison...
function genericOrUndefined<T>(): T | undefined {
>genericOrUndefined : Symbol(genericOrUndefined, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 9, 1))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 13, 28))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 13, 28))
return 0 as any;
}
function JustGeneric<T>(): T {
>JustGeneric : Symbol(JustGeneric, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 15, 1))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 17, 21))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 17, 21))
return genericOrUndefined<T>()!; // no error
>genericOrUndefined : Symbol(genericOrUndefined, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 9, 1))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 17, 21))
}
// Simplified example:
function f<T>() {
>f : Symbol(f, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 19, 1))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 23, 11))
type One = T extends string ? string : string;
>One : Symbol(One, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 23, 17))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 23, 11))
type A = T extends number ? One : never;
>A : Symbol(A, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 24, 50))
>T : Symbol(T, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 23, 11))
>One : Symbol(One, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 23, 17))
const x: One = null as any as A;
>x : Symbol(x, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 26, 9))
>One : Symbol(One, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 23, 17))
>A : Symbol(A, Decl(simplifyingConditionalWithInteriorConditionalIsRelated.ts, 24, 50))
}
|