Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Accept new baselines
  • Loading branch information
ahejlsberg committed May 11, 2019
1 parent 71fe8e8 commit 33c7e7f
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 105 deletions.
4 changes: 2 additions & 2 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Expand Up @@ -2390,8 +2390,8 @@ declare namespace ts {
root: ConditionalRoot;
checkType: Type;
extendsType: Type;
trueType: Type;
falseType: Type;
resolvedTrueType: Type;
resolvedFalseType: Type;
}
interface SubstitutionType extends InstantiableType {
typeVariable: TypeVariable;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/api/typescript.d.ts
Expand Up @@ -2390,8 +2390,8 @@ declare namespace ts {
root: ConditionalRoot;
checkType: Type;
extendsType: Type;
trueType: Type;
falseType: Type;
resolvedTrueType: Type;
resolvedFalseType: Type;
}
interface SubstitutionType extends InstantiableType {
typeVariable: TypeVariable;
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/baselines/reference/conditionalTypes1.js
Expand Up @@ -645,7 +645,7 @@ declare type T82 = Eq2<false, true>;
declare type T83 = Eq2<false, false>;
declare type Foo<T> = T extends string ? boolean : number;
declare type Bar<T> = T extends string ? boolean : number;
declare const convert: <U>(value: Foo<U>) => Foo<U>;
declare const convert: <U>(value: Foo<U>) => Bar<U>;
declare type Baz<T> = Foo<T>;
declare const convert2: <T>(value: Foo<T>) => Foo<T>;
declare function f31<T>(): void;
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/conditionalTypes1.types
Expand Up @@ -779,8 +779,8 @@ type Bar<T> = T extends string ? boolean : number;
>Bar : Bar<T>

const convert = <U>(value: Foo<U>): Bar<U> => value;
>convert : <U>(value: Foo<U>) => Foo<U>
><U>(value: Foo<U>): Bar<U> => value : <U>(value: Foo<U>) => Foo<U>
>convert : <U>(value: Foo<U>) => Bar<U>
><U>(value: Foo<U>): Bar<U> => value : <U>(value: Foo<U>) => Bar<U>
>value : Foo<U>
>value : Foo<U>

Expand Down Expand Up @@ -832,7 +832,7 @@ function f33<T, U>() {
>T1 : Foo<T & U>

type T2 = Bar<T & U>;
>T2 : Foo<T & U>
>T2 : Bar<T & U>

var z: T1;
>z : Foo<T & U>
Expand Down
@@ -0,0 +1,100 @@
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(27,14): error TS2322: Type 'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>' is not assignable to type 'Params'.
'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(31,5): error TS2322: Type 'T' is not assignable to type 'ExcludeWithDefault<T, never, never>'.
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(36,14): error TS2322: Type 'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>' is not assignable to type 'Params'.
'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(40,5): error TS2322: Type 'T' is not assignable to type 'ExtractWithDefault<T, T, never>'.
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(47,14): error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>' is not assignable to type 'Params'.
'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(51,5): error TS2322: Type 'T' is not assignable to type 'TemplatedConditional<T, never, never, T>'.
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(56,14): error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>' is not assignable to type 'Params'.
'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.
tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(60,5): error TS2322: Type 'T' is not assignable to type 'TemplatedConditional<T, T, T, never>'.


==== tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts (8 errors) ====
const fn1 = <Params>(
params: Pick<Params, Exclude<keyof Params, never>>,
): Params => params;

function fn2<T>(x: Exclude<T, never>) {
var y: T = x;
x = y;
}

const fn3 = <Params>(
params: Pick<Params, Extract<keyof Params, keyof Params>>,
): Params => params;

function fn4<T>(x: Extract<T, T>) {
var y: T = x;
x = y;
}

declare var x: Extract<number | string, any>; // Should be `numebr | string` and not `any`

type ExtractWithDefault<T, U, D = never> = T extends U ? T : D;

type ExcludeWithDefault<T, U, D = never> = T extends U ? D : T;

const fn5 = <Params>(
params: Pick<Params, ExcludeWithDefault<keyof Params, never>>,
): Params => params;
~~~~~~
!!! error TS2322: Type 'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>' is not assignable to type 'Params'.
!!! error TS2322: 'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.

function fn6<T>(x: ExcludeWithDefault<T, never>) {
var y: T = x;
x = y;
~
!!! error TS2322: Type 'T' is not assignable to type 'ExcludeWithDefault<T, never, never>'.
}

const fn7 = <Params>(
params: Pick<Params, ExtractWithDefault<keyof Params, keyof Params>>,
): Params => params;
~~~~~~
!!! error TS2322: Type 'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>' is not assignable to type 'Params'.
!!! error TS2322: 'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.

function fn8<T>(x: ExtractWithDefault<T, T>) {
var y: T = x;
x = y;
~
!!! error TS2322: Type 'T' is not assignable to type 'ExtractWithDefault<T, T, never>'.
}

type TemplatedConditional<TCheck, TExtends, TTrue, TFalse> = TCheck extends TExtends ? TTrue : TFalse;

const fn9 = <Params>(
params: Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>,
): Params => params;
~~~~~~
!!! error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>' is not assignable to type 'Params'.
!!! error TS2322: 'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.

function fn10<T>(x: TemplatedConditional<T, never, never, T>) {
var y: T = x;
x = y;
~
!!! error TS2322: Type 'T' is not assignable to type 'TemplatedConditional<T, never, never, T>'.
}

const fn11 = <Params>(
params: Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>,
): Params => params;
~~~~~~
!!! error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>' is not assignable to type 'Params'.
!!! error TS2322: 'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>' is assignable to the constraint of type 'Params', but 'Params' could be instantiated with a different subtype of constraint '{}'.

function fn12<T>(x: TemplatedConditional<T, T, T, never>) {
var y: T = x;
x = y;
~
!!! error TS2322: Type 'T' is not assignable to type 'TemplatedConditional<T, T, T, never>'.
}

declare var z: any;
const zee = z!!!; // since x is `any`, `x extends null | undefined` should be both true and false - and thus yield `any`

64 changes: 32 additions & 32 deletions tests/baselines/reference/conditionalTypesSimplifyWhenTrivial.types
Expand Up @@ -57,101 +57,101 @@ type ExcludeWithDefault<T, U, D = never> = T extends U ? D : T;
>ExcludeWithDefault : ExcludeWithDefault<T, U, D>

const fn5 = <Params>(
>fn5 : <Params>(params: Pick<Params, keyof Params>) => Params
><Params>( params: Pick<Params, ExcludeWithDefault<keyof Params, never>>,): Params => params : <Params>(params: Pick<Params, keyof Params>) => Params
>fn5 : <Params>(params: Pick<Params, ExcludeWithDefault<keyof Params, never, never>>) => Params
><Params>( params: Pick<Params, ExcludeWithDefault<keyof Params, never>>,): Params => params : <Params>(params: Pick<Params, ExcludeWithDefault<keyof Params, never, never>>) => Params

params: Pick<Params, ExcludeWithDefault<keyof Params, never>>,
>params : Pick<Params, keyof Params>
>params : Pick<Params, ExcludeWithDefault<keyof Params, never, never>>

): Params => params;
>params : Pick<Params, keyof Params>
>params : Pick<Params, ExcludeWithDefault<keyof Params, never, never>>

function fn6<T>(x: ExcludeWithDefault<T, never>) {
>fn6 : <T>(x: T) => void
>x : T
>fn6 : <T>(x: ExcludeWithDefault<T, never, never>) => void
>x : ExcludeWithDefault<T, never, never>

var y: T = x;
>y : T
>x : T
>x : ExcludeWithDefault<T, never, never>

x = y;
>x = y : T
>x : T
>x : ExcludeWithDefault<T, never, never>
>y : T
}

const fn7 = <Params>(
>fn7 : <Params>(params: Pick<Params, keyof Params>) => Params
><Params>( params: Pick<Params, ExtractWithDefault<keyof Params, keyof Params>>,): Params => params : <Params>(params: Pick<Params, keyof Params>) => Params
>fn7 : <Params>(params: Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>) => Params
><Params>( params: Pick<Params, ExtractWithDefault<keyof Params, keyof Params>>,): Params => params : <Params>(params: Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>) => Params

params: Pick<Params, ExtractWithDefault<keyof Params, keyof Params>>,
>params : Pick<Params, keyof Params>
>params : Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>

): Params => params;
>params : Pick<Params, keyof Params>
>params : Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>

function fn8<T>(x: ExtractWithDefault<T, T>) {
>fn8 : <T>(x: T) => void
>x : T
>fn8 : <T>(x: ExtractWithDefault<T, T, never>) => void
>x : ExtractWithDefault<T, T, never>

var y: T = x;
>y : T
>x : T
>x : ExtractWithDefault<T, T, never>

x = y;
>x = y : T
>x : T
>x : ExtractWithDefault<T, T, never>
>y : T
}

type TemplatedConditional<TCheck, TExtends, TTrue, TFalse> = TCheck extends TExtends ? TTrue : TFalse;
>TemplatedConditional : TemplatedConditional<TCheck, TExtends, TTrue, TFalse>

const fn9 = <Params>(
>fn9 : <Params>(params: Pick<Params, keyof Params>) => Params
><Params>( params: Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>,): Params => params : <Params>(params: Pick<Params, keyof Params>) => Params
>fn9 : <Params>(params: Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>) => Params
><Params>( params: Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>,): Params => params : <Params>(params: Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>) => Params

params: Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>,
>params : Pick<Params, keyof Params>
>params : Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>

): Params => params;
>params : Pick<Params, keyof Params>
>params : Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>

function fn10<T>(x: TemplatedConditional<T, never, never, T>) {
>fn10 : <T>(x: T) => void
>x : T
>fn10 : <T>(x: TemplatedConditional<T, never, never, T>) => void
>x : TemplatedConditional<T, never, never, T>

var y: T = x;
>y : T
>x : T
>x : TemplatedConditional<T, never, never, T>

x = y;
>x = y : T
>x : T
>x : TemplatedConditional<T, never, never, T>
>y : T
}

const fn11 = <Params>(
>fn11 : <Params>(params: Pick<Params, keyof Params>) => Params
><Params>( params: Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>,): Params => params : <Params>(params: Pick<Params, keyof Params>) => Params
>fn11 : <Params>(params: Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>) => Params
><Params>( params: Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>,): Params => params : <Params>(params: Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>) => Params

params: Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>,
>params : Pick<Params, keyof Params>
>params : Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>

): Params => params;
>params : Pick<Params, keyof Params>
>params : Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>

function fn12<T>(x: TemplatedConditional<T, T, T, never>) {
>fn12 : <T>(x: T) => void
>x : T
>fn12 : <T>(x: TemplatedConditional<T, T, T, never>) => void
>x : TemplatedConditional<T, T, T, never>

var y: T = x;
>y : T
>x : T
>x : TemplatedConditional<T, T, T, never>

x = y;
>x = y : T
>x : T
>x : TemplatedConditional<T, T, T, never>
>y : T
}

Expand Down
Expand Up @@ -31,7 +31,7 @@ class A {
>z : A[]

whereRelated< // Works // Type is same as A1, but is not assignable to type A
>whereRelated : <RF extends RelationFields = RelationFields, N extends "x" | "y" | "z" = "x" | "y" | "z", A1 extends A = RF[N] extends A[] ? RF[N][0] : never, A2 extends A = RF[N] extends A[] ? RF[N][0] : never>() => number
>whereRelated : <RF extends RelationFields = RelationFields, N extends "x" | "y" | "z" = "x" | "y" | "z", A1 extends A = RF[N] extends A[] ? RF[N][0] : never, A2 extends A = ShouldA<RF, N>>() => number

RF extends RelationFields = RelationFields,
N extends Name = Name,
Expand Down

0 comments on commit 33c7e7f

Please sign in to comment.