Accepted baselines.

This commit is contained in:
Daniel Rosenwasser 2019-05-01 16:07:29 -07:00
parent d9e82466e2
commit d7434a01b2
13 changed files with 101 additions and 74 deletions

View file

@ -2,18 +2,18 @@
// Repro from #29067
function test<T extends { a: string }>(obj: T) {
>test : <T extends { a: string; }>(obj: T) => Omit<T, "a"> & { b: string; }
>test : <T extends { a: string; }>(obj: T) => Pick<T, Exclude<keyof T, "a">> & { b: string; }
>a : string
>obj : T
let { a, ...rest } = obj;
>a : string
>rest : Omit<T, "a">
>rest : Pick<T, Exclude<keyof T, "a">>
>obj : T
return { ...rest, b: a };
>{ ...rest, b: a } : Omit<T, "a"> & { b: string; }
>rest : Omit<T, "a">
>{ ...rest, b: a } : Pick<T, Exclude<keyof T, "a">> & { b: string; }
>rest : Pick<T, Exclude<keyof T, "a">>
>b : string
>a : string
}
@ -30,7 +30,7 @@ let o2: { b: string, x: number } = test(o1);
>o2 : { b: string; x: number; }
>b : string
>x : number
>test(o1) : Omit<{ a: string; x: number; }, "a"> & { b: string; }
>test : <T extends { a: string; }>(obj: T) => Omit<T, "a"> & { b: string; }
>test(o1) : Pick<{ a: string; x: number; }, "x"> & { b: string; }
>test : <T extends { a: string; }>(obj: T) => Pick<T, Exclude<keyof T, "a">> & { b: string; }
>o1 : { a: string; x: number; }

View file

@ -16,7 +16,7 @@ function f1<T extends { a: string, b: number }>(obj: T) {
let { a: a1, ...r1 } = obj;
>a : any
>a1 : string
>r1 : Omit<T, "a">
>r1 : Pick<T, Exclude<keyof T, "a">>
>obj : T
let { a: a2, b: b2, ...r2 } = obj;
@ -24,24 +24,24 @@ function f1<T extends { a: string, b: number }>(obj: T) {
>a2 : string
>b : any
>b2 : number
>r2 : Omit<T, "a" | "b">
>r2 : Pick<T, Exclude<keyof T, "a" | "b">>
>obj : T
let { 'a': a3, ...r3 } = obj;
>a3 : string
>r3 : Omit<T, "a">
>r3 : Pick<T, Exclude<keyof T, "a">>
>obj : T
let { ['a']: a4, ...r4 } = obj;
>'a' : "a"
>a4 : string
>r4 : Omit<T, "a">
>r4 : Pick<T, Exclude<keyof T, "a">>
>obj : T
let { [a]: a5, ...r5 } = obj;
>a : "a"
>a5 : string
>r5 : Omit<T, "a">
>r5 : Pick<T, Exclude<keyof T, "a">>
>obj : T
}
@ -68,7 +68,7 @@ function f2<T extends { [sa]: string, [sb]: number }>(obj: T) {
>a1 : string
>sb : unique symbol
>b1 : number
>r1 : Omit<T, unique symbol | unique symbol>
>r1 : Pick<T, Exclude<keyof T, unique symbol | unique symbol>>
>obj : T
}
@ -83,7 +83,7 @@ function f3<T, K1 extends keyof T, K2 extends keyof T>(obj: T, k1: K1, k2: K2) {
>a1 : T[K1]
>k2 : K2
>a2 : T[K2]
>r1 : Omit<T, K1 | K2>
>r1 : Pick<T, Exclude<keyof T, K1 | K2>>
>obj : T
}
@ -104,7 +104,7 @@ function f4<K1 extends keyof Item, K2 extends keyof Item>(obj: Item, k1: K1, k2:
>a1 : Item[K1]
>k2 : K2
>a2 : Item[K2]
>r1 : Omit<Item, K1 | K2>
>r1 : Pick<Item, Exclude<"a", K1 | K2> | Exclude<"b", K1 | K2> | Exclude<"c", K1 | K2>>
>obj : Item
}

View file

@ -443,14 +443,14 @@ function test<T extends { a: string, b: string }>(obj: T): T {
let { a, ...rest } = obj;
>a : string
>rest : Omit<T, "a">
>rest : Pick<T, Exclude<keyof T, "a">>
>obj : T
return { a: 'hello', ...rest } as T;
>{ a: 'hello', ...rest } as T : T
>{ a: 'hello', ...rest } : { a: string; } & Omit<T, "a">
>{ a: 'hello', ...rest } : { a: string; } & Pick<T, Exclude<keyof T, "a">>
>a : string
>'hello' : "hello"
>rest : Omit<T, "a">
>rest : Pick<T, Exclude<keyof T, "a">>
}

View file

@ -132,9 +132,9 @@ const modifier = <T extends TargetProps>(targetProps: T) => {
>targetProps : Symbol(targetProps, Decl(mappedTypeConstraints.ts, 30, 41))
rest.foo;
>rest.foo : Symbol(foo)
>rest.foo : Symbol(foo, Decl(mappedTypeConstraints.ts, 25, 20))
>rest : Symbol(rest, Decl(mappedTypeConstraints.ts, 31, 13))
>foo : Symbol(foo)
>foo : Symbol(foo, Decl(mappedTypeConstraints.ts, 25, 20))
};

View file

@ -98,12 +98,12 @@ const modifier = <T extends TargetProps>(targetProps: T) => {
let {bar, ...rest} = targetProps;
>bar : string
>rest : Omit<T, "bar">
>rest : Pick<T, Exclude<keyof T, "bar">>
>targetProps : T
rest.foo;
>rest.foo : T["foo"]
>rest : Omit<T, "bar">
>rest : Pick<T, Exclude<keyof T, "bar">>
>foo : T["foo"]
};

View file

@ -36,18 +36,18 @@ function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void {
>b : string
}
function generic<T extends { x, y }>(t: T) {
>generic : <T extends { x: any; y: any; }>(t: T) => Omit<T, "x">
>generic : <T extends { x: any; y: any; }>(t: T) => Pick<T, Exclude<keyof T, "x">>
>x : any
>y : any
>t : T
let { x, ...rest } = t;
>x : any
>rest : Omit<T, "x">
>rest : Pick<T, Exclude<keyof T, "x">>
>t : T
return rest;
>rest : Omit<T, "x">
>rest : Pick<T, Exclude<keyof T, "x">>
}
let rest: { b: string }

View file

@ -0,0 +1,27 @@
tests/cases/compiler/omitTypeHelperModifiers01.ts(16,7): error TS2540: Cannot assign to 'c' because it is a read-only property.
==== tests/cases/compiler/omitTypeHelperModifiers01.ts (1 errors) ====
type A = {
a: number;
b?: string;
readonly c: boolean;
d: unknown;
};
type B = Omit<A, 'a'>;
function f(x: B) {
const b = x.b;
x.b = "hello";
x.b = undefined;
const c = x.c;
x.c = true;
~
!!! error TS2540: Cannot assign to 'c' because it is a read-only property.
const d = x.d;
x.d = d;
}

View file

@ -28,42 +28,42 @@ function f(x: B) {
const b = x.b;
>b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 10, 9))
>x.b : Symbol(b)
>x.b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14))
>x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11))
>b : Symbol(b)
>b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14))
x.b = "hello";
>x.b : Symbol(b)
>x.b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14))
>x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11))
>b : Symbol(b)
>b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14))
x.b = undefined;
>x.b : Symbol(b)
>x.b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14))
>x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11))
>b : Symbol(b)
>b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14))
>undefined : Symbol(undefined)
const c = x.c;
>c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 14, 9))
>x.c : Symbol(c)
>x.c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15))
>x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11))
>c : Symbol(c)
>c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15))
x.c = true;
>x.c : Symbol(c)
>x.c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15))
>x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11))
>c : Symbol(c)
>c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15))
const d = x.d;
>d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 17, 9))
>x.d : Symbol(d)
>x.d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24))
>x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11))
>d : Symbol(d)
>d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24))
x.d = d;
>x.d : Symbol(d)
>x.d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24))
>x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11))
>d : Symbol(d)
>d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24))
>d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 17, 9))
}

View file

@ -17,55 +17,55 @@ type A = {
};
type B = Omit<A, 'a'>;
>B : Omit<A, "a">
>B : Pick<A, "b" | "c" | "d">
function f(x: B) {
>f : (x: Omit<A, "a">) => void
>x : Omit<A, "a">
>f : (x: Pick<A, "b" | "c" | "d">) => void
>x : Pick<A, "b" | "c" | "d">
const b = x.b;
>b : string | undefined
>x.b : string | undefined
>x : Omit<A, "a">
>x : Pick<A, "b" | "c" | "d">
>b : string | undefined
x.b = "hello";
>x.b = "hello" : "hello"
>x.b : string | undefined
>x : Omit<A, "a">
>x : Pick<A, "b" | "c" | "d">
>b : string | undefined
>"hello" : "hello"
x.b = undefined;
>x.b = undefined : undefined
>x.b : string | undefined
>x : Omit<A, "a">
>x : Pick<A, "b" | "c" | "d">
>b : string | undefined
>undefined : undefined
const c = x.c;
>c : boolean
>x.c : boolean
>x : Omit<A, "a">
>x : Pick<A, "b" | "c" | "d">
>c : boolean
x.c = true;
>x.c = true : true
>x.c : boolean
>x : Omit<A, "a">
>c : boolean
>x.c : any
>x : Pick<A, "b" | "c" | "d">
>c : any
>true : true
const d = x.d;
>d : unknown
>x.d : unknown
>x : Omit<A, "a">
>x : Pick<A, "b" | "c" | "d">
>d : unknown
x.d = d;
>x.d = d : unknown
>x.d : unknown
>x : Omit<A, "a">
>x : Pick<A, "b" | "c" | "d">
>d : unknown
>d : unknown
}

View file

@ -1,5 +1,5 @@
tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Omit<Foo, "c">'.
tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Omit<Foo, "c" | "b">'.
tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Pick<Foo, "a" | "b">'.
tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Pick<Foo, "a">'.
==== tests/cases/compiler/omitTypeTestErrors01.ts (2 errors) ====
@ -15,13 +15,13 @@ tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b'
export function getBarC(bar: Bar) {
return bar.c;
~
!!! error TS2339: Property 'c' does not exist on type 'Omit<Foo, "c">'.
!!! error TS2339: Property 'c' does not exist on type 'Pick<Foo, "a" | "b">'.
}
export function getBazB(baz: Baz) {
return baz.b;
~
!!! error TS2339: Property 'b' does not exist on type 'Omit<Foo, "c" | "b">'.
!!! error TS2339: Property 'b' does not exist on type 'Pick<Foo, "a">'.
}

View file

@ -11,28 +11,28 @@ interface Foo {
}
export type Bar = Omit<Foo, "c">;
>Bar : Omit<Foo, "c">
>Bar : Pick<Foo, "a" | "b">
export type Baz = Omit<Foo, "b" | "c">;
>Baz : Omit<Foo, "c" | "b">
>Baz : Pick<Foo, "a">
export function getBarC(bar: Bar) {
>getBarC : (bar: Omit<Foo, "c">) => any
>bar : Omit<Foo, "c">
>getBarC : (bar: Pick<Foo, "a" | "b">) => any
>bar : Pick<Foo, "a" | "b">
return bar.c;
>bar.c : any
>bar : Omit<Foo, "c">
>bar : Pick<Foo, "a" | "b">
>c : any
}
export function getBazB(baz: Baz) {
>getBazB : (baz: Omit<Foo, "c" | "b">) => any
>baz : Omit<Foo, "c" | "b">
>getBazB : (baz: Pick<Foo, "a">) => any
>baz : Pick<Foo, "a">
return baz.b;
>baz.b : any
>baz : Omit<Foo, "c" | "b">
>baz : Pick<Foo, "a">
>b : any
}

View file

@ -28,9 +28,9 @@ export function getBarA(bar: Bar) {
>Bar : Symbol(Bar, Decl(omitTypeTests01.ts, 4, 1))
return bar.a;
>bar.a : Symbol(a)
>bar.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15))
>bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24))
>a : Symbol(a)
>a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15))
}
export function getBazA(baz: Baz) {
@ -39,9 +39,9 @@ export function getBazA(baz: Baz) {
>Baz : Symbol(Baz, Decl(omitTypeTests01.ts, 6, 33))
return baz.a;
>baz.a : Symbol(a)
>baz.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15))
>baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24))
>a : Symbol(a)
>a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15))
}

View file

@ -11,28 +11,28 @@ interface Foo {
}
export type Bar = Omit<Foo, "c">;
>Bar : Omit<Foo, "c">
>Bar : Pick<Foo, "a" | "b">
export type Baz = Omit<Foo, "b" | "c">;
>Baz : Omit<Foo, "c" | "b">
>Baz : Pick<Foo, "a">
export function getBarA(bar: Bar) {
>getBarA : (bar: Omit<Foo, "c">) => string
>bar : Omit<Foo, "c">
>getBarA : (bar: Pick<Foo, "a" | "b">) => string
>bar : Pick<Foo, "a" | "b">
return bar.a;
>bar.a : string
>bar : Omit<Foo, "c">
>bar : Pick<Foo, "a" | "b">
>a : string
}
export function getBazA(baz: Baz) {
>getBazA : (baz: Omit<Foo, "c" | "b">) => string
>baz : Omit<Foo, "c" | "b">
>getBazA : (baz: Pick<Foo, "a">) => string
>baz : Pick<Foo, "a">
return baz.a;
>baz.a : string
>baz : Omit<Foo, "c" | "b">
>baz : Pick<Foo, "a">
>a : string
}