Skip to content

Commit

Permalink
Add regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Oct 11, 2022
1 parent 52e9cae commit 72a0f3b
Show file tree
Hide file tree
Showing 5 changed files with 339 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/baselines/reference/nestedExcessPropertyChecking.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
tests/cases/compiler/nestedExcessPropertyChecking.ts(6,7): error TS2322: Type 'C1' is not assignable to type 'A1 & B1'.
Types of property 'x' are incompatible.
Type '{ c: string; }' has no properties in common with type '{ a?: string | undefined; } & { b?: string | undefined; }'.
tests/cases/compiler/nestedExcessPropertyChecking.ts(13,7): error TS2559: Type 'C2' has no properties in common with type 'A2 & B2'.
tests/cases/compiler/nestedExcessPropertyChecking.ts(25,22): error TS2559: Type 'false' has no properties in common with type 'OverridesInput'.
tests/cases/compiler/nestedExcessPropertyChecking.ts(35,9): error TS2559: Type 'false' has no properties in common with type 'OverridesInput'.


==== tests/cases/compiler/nestedExcessPropertyChecking.ts (4 errors) ====
type A1 = { x: { a?: string } };
type B1 = { x: { b?: string } };

type C1 = { x: { c: string } };

const ab1: A1 & B1 = {} as C1; // Error
~~~
!!! error TS2322: Type 'C1' is not assignable to type 'A1 & B1'.
!!! error TS2322: Types of property 'x' are incompatible.
!!! error TS2322: Type '{ c: string; }' has no properties in common with type '{ a?: string | undefined; } & { b?: string | undefined; }'.

type A2 = { a?: string };
type B2 = { b?: string };

type C2 = { c: string };

const ab2: A2 & B2 = {} as C2; // Error
~~~
!!! error TS2559: Type 'C2' has no properties in common with type 'A2 & B2'.

// Repros from #51043

type OverridesInput = {
someProp?: 'A' | 'B'
}

const foo1: Partial<{ something: any }> & { variables: {
overrides?: OverridesInput;
} & Partial<{
overrides?: OverridesInput;
}>} = { variables: { overrides: false } }; // Error
~~~~~~~~~
!!! error TS2559: Type 'false' has no properties in common with type 'OverridesInput'.
!!! related TS6500 tests/cases/compiler/nestedExcessPropertyChecking.ts:22:5: The expected type comes from property 'overrides' which is declared here on type '{ overrides?: OverridesInput | undefined; } & Partial<{ overrides?: OverridesInput | undefined; }>'


interface Unrelated { _?: any }

interface VariablesA { overrides?: OverridesInput; }
interface VariablesB { overrides?: OverridesInput; }

const foo2: Unrelated & { variables: VariablesA & VariablesB } = {
variables: {
overrides: false // Error
~~~~~~~~~
!!! error TS2559: Type 'false' has no properties in common with type 'OverridesInput'.
!!! related TS6500 tests/cases/compiler/nestedExcessPropertyChecking.ts:30:24: The expected type comes from property 'overrides' which is declared here on type 'VariablesA & VariablesB'
}
};

50 changes: 50 additions & 0 deletions tests/baselines/reference/nestedExcessPropertyChecking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//// [nestedExcessPropertyChecking.ts]
type A1 = { x: { a?: string } };
type B1 = { x: { b?: string } };

type C1 = { x: { c: string } };

const ab1: A1 & B1 = {} as C1; // Error

type A2 = { a?: string };
type B2 = { b?: string };

type C2 = { c: string };

const ab2: A2 & B2 = {} as C2; // Error

// Repros from #51043

type OverridesInput = {
someProp?: 'A' | 'B'
}

const foo1: Partial<{ something: any }> & { variables: {
overrides?: OverridesInput;
} & Partial<{
overrides?: OverridesInput;
}>} = { variables: { overrides: false } }; // Error


interface Unrelated { _?: any }

interface VariablesA { overrides?: OverridesInput; }
interface VariablesB { overrides?: OverridesInput; }

const foo2: Unrelated & { variables: VariablesA & VariablesB } = {
variables: {
overrides: false // Error
}
};


//// [nestedExcessPropertyChecking.js]
"use strict";
var ab1 = {}; // Error
var ab2 = {}; // Error
var foo1 = { variables: { overrides: false } }; // Error
var foo2 = {
variables: {
overrides: false // Error
}
};
100 changes: 100 additions & 0 deletions tests/baselines/reference/nestedExcessPropertyChecking.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
=== tests/cases/compiler/nestedExcessPropertyChecking.ts ===
type A1 = { x: { a?: string } };
>A1 : Symbol(A1, Decl(nestedExcessPropertyChecking.ts, 0, 0))
>x : Symbol(x, Decl(nestedExcessPropertyChecking.ts, 0, 11))
>a : Symbol(a, Decl(nestedExcessPropertyChecking.ts, 0, 16))

type B1 = { x: { b?: string } };
>B1 : Symbol(B1, Decl(nestedExcessPropertyChecking.ts, 0, 32))
>x : Symbol(x, Decl(nestedExcessPropertyChecking.ts, 1, 11))
>b : Symbol(b, Decl(nestedExcessPropertyChecking.ts, 1, 16))

type C1 = { x: { c: string } };
>C1 : Symbol(C1, Decl(nestedExcessPropertyChecking.ts, 1, 32))
>x : Symbol(x, Decl(nestedExcessPropertyChecking.ts, 3, 11))
>c : Symbol(c, Decl(nestedExcessPropertyChecking.ts, 3, 16))

const ab1: A1 & B1 = {} as C1; // Error
>ab1 : Symbol(ab1, Decl(nestedExcessPropertyChecking.ts, 5, 5))
>A1 : Symbol(A1, Decl(nestedExcessPropertyChecking.ts, 0, 0))
>B1 : Symbol(B1, Decl(nestedExcessPropertyChecking.ts, 0, 32))
>C1 : Symbol(C1, Decl(nestedExcessPropertyChecking.ts, 1, 32))

type A2 = { a?: string };
>A2 : Symbol(A2, Decl(nestedExcessPropertyChecking.ts, 5, 30))
>a : Symbol(a, Decl(nestedExcessPropertyChecking.ts, 7, 11))

type B2 = { b?: string };
>B2 : Symbol(B2, Decl(nestedExcessPropertyChecking.ts, 7, 25))
>b : Symbol(b, Decl(nestedExcessPropertyChecking.ts, 8, 11))

type C2 = { c: string };
>C2 : Symbol(C2, Decl(nestedExcessPropertyChecking.ts, 8, 25))
>c : Symbol(c, Decl(nestedExcessPropertyChecking.ts, 10, 11))

const ab2: A2 & B2 = {} as C2; // Error
>ab2 : Symbol(ab2, Decl(nestedExcessPropertyChecking.ts, 12, 5))
>A2 : Symbol(A2, Decl(nestedExcessPropertyChecking.ts, 5, 30))
>B2 : Symbol(B2, Decl(nestedExcessPropertyChecking.ts, 7, 25))
>C2 : Symbol(C2, Decl(nestedExcessPropertyChecking.ts, 8, 25))

// Repros from #51043

type OverridesInput = {
>OverridesInput : Symbol(OverridesInput, Decl(nestedExcessPropertyChecking.ts, 12, 30))

someProp?: 'A' | 'B'
>someProp : Symbol(someProp, Decl(nestedExcessPropertyChecking.ts, 16, 23))
}

const foo1: Partial<{ something: any }> & { variables: {
>foo1 : Symbol(foo1, Decl(nestedExcessPropertyChecking.ts, 20, 5))
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
>something : Symbol(something, Decl(nestedExcessPropertyChecking.ts, 20, 21))
>variables : Symbol(variables, Decl(nestedExcessPropertyChecking.ts, 20, 43))

overrides?: OverridesInput;
>overrides : Symbol(overrides, Decl(nestedExcessPropertyChecking.ts, 20, 56))
>OverridesInput : Symbol(OverridesInput, Decl(nestedExcessPropertyChecking.ts, 12, 30))

} & Partial<{
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))

overrides?: OverridesInput;
>overrides : Symbol(overrides, Decl(nestedExcessPropertyChecking.ts, 22, 13))
>OverridesInput : Symbol(OverridesInput, Decl(nestedExcessPropertyChecking.ts, 12, 30))

}>} = { variables: { overrides: false } }; // Error
>variables : Symbol(variables, Decl(nestedExcessPropertyChecking.ts, 24, 7))
>overrides : Symbol(overrides, Decl(nestedExcessPropertyChecking.ts, 24, 20))


interface Unrelated { _?: any }
>Unrelated : Symbol(Unrelated, Decl(nestedExcessPropertyChecking.ts, 24, 42))
>_ : Symbol(Unrelated._, Decl(nestedExcessPropertyChecking.ts, 27, 21))

interface VariablesA { overrides?: OverridesInput; }
>VariablesA : Symbol(VariablesA, Decl(nestedExcessPropertyChecking.ts, 27, 31))
>overrides : Symbol(VariablesA.overrides, Decl(nestedExcessPropertyChecking.ts, 29, 22))
>OverridesInput : Symbol(OverridesInput, Decl(nestedExcessPropertyChecking.ts, 12, 30))

interface VariablesB { overrides?: OverridesInput; }
>VariablesB : Symbol(VariablesB, Decl(nestedExcessPropertyChecking.ts, 29, 52))
>overrides : Symbol(VariablesB.overrides, Decl(nestedExcessPropertyChecking.ts, 30, 22))
>OverridesInput : Symbol(OverridesInput, Decl(nestedExcessPropertyChecking.ts, 12, 30))

const foo2: Unrelated & { variables: VariablesA & VariablesB } = {
>foo2 : Symbol(foo2, Decl(nestedExcessPropertyChecking.ts, 32, 5))
>Unrelated : Symbol(Unrelated, Decl(nestedExcessPropertyChecking.ts, 24, 42))
>variables : Symbol(variables, Decl(nestedExcessPropertyChecking.ts, 32, 25))
>VariablesA : Symbol(VariablesA, Decl(nestedExcessPropertyChecking.ts, 27, 31))
>VariablesB : Symbol(VariablesB, Decl(nestedExcessPropertyChecking.ts, 29, 52))

variables: {
>variables : Symbol(variables, Decl(nestedExcessPropertyChecking.ts, 32, 66))

overrides: false // Error
>overrides : Symbol(overrides, Decl(nestedExcessPropertyChecking.ts, 33, 16))
}
};

91 changes: 91 additions & 0 deletions tests/baselines/reference/nestedExcessPropertyChecking.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
=== tests/cases/compiler/nestedExcessPropertyChecking.ts ===
type A1 = { x: { a?: string } };
>A1 : { x: { a?: string;}; }
>x : { a?: string | undefined; }
>a : string | undefined

type B1 = { x: { b?: string } };
>B1 : { x: { b?: string;}; }
>x : { b?: string | undefined; }
>b : string | undefined

type C1 = { x: { c: string } };
>C1 : { x: { c: string;}; }
>x : { c: string; }
>c : string

const ab1: A1 & B1 = {} as C1; // Error
>ab1 : A1 & B1
>{} as C1 : C1
>{} : {}

type A2 = { a?: string };
>A2 : { a?: string | undefined; }
>a : string | undefined

type B2 = { b?: string };
>B2 : { b?: string | undefined; }
>b : string | undefined

type C2 = { c: string };
>C2 : { c: string; }
>c : string

const ab2: A2 & B2 = {} as C2; // Error
>ab2 : A2 & B2
>{} as C2 : C2
>{} : {}

// Repros from #51043

type OverridesInput = {
>OverridesInput : { someProp?: "A" | "B" | undefined; }

someProp?: 'A' | 'B'
>someProp : "A" | "B" | undefined
}

const foo1: Partial<{ something: any }> & { variables: {
>foo1 : Partial<{ something: any; }> & { variables: { overrides?: OverridesInput;} & Partial<{ overrides?: OverridesInput;}>; }
>something : any
>variables : { overrides?: OverridesInput | undefined; } & Partial<{ overrides?: OverridesInput | undefined; }>

overrides?: OverridesInput;
>overrides : OverridesInput | undefined

} & Partial<{
overrides?: OverridesInput;
>overrides : OverridesInput | undefined

}>} = { variables: { overrides: false } }; // Error
>{ variables: { overrides: false } } : { variables: { overrides: boolean; }; }
>variables : { overrides: boolean; }
>{ overrides: false } : { overrides: boolean; }
>overrides : boolean
>false : false


interface Unrelated { _?: any }
>_ : any

interface VariablesA { overrides?: OverridesInput; }
>overrides : OverridesInput | undefined

interface VariablesB { overrides?: OverridesInput; }
>overrides : OverridesInput | undefined

const foo2: Unrelated & { variables: VariablesA & VariablesB } = {
>foo2 : Unrelated & { variables: VariablesA & VariablesB; }
>variables : VariablesA & VariablesB
>{ variables: { overrides: false // Error }} : { variables: { overrides: boolean; }; }

variables: {
>variables : { overrides: boolean; }
>{ overrides: false // Error } : { overrides: boolean; }

overrides: false // Error
>overrides : boolean
>false : false
}
};

39 changes: 39 additions & 0 deletions tests/cases/compiler/nestedExcessPropertyChecking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @strict: true

type A1 = { x: { a?: string } };
type B1 = { x: { b?: string } };

type C1 = { x: { c: string } };

const ab1: A1 & B1 = {} as C1; // Error

type A2 = { a?: string };
type B2 = { b?: string };

type C2 = { c: string };

const ab2: A2 & B2 = {} as C2; // Error

// Repros from #51043

type OverridesInput = {
someProp?: 'A' | 'B'
}

const foo1: Partial<{ something: any }> & { variables: {
overrides?: OverridesInput;
} & Partial<{
overrides?: OverridesInput;
}>} = { variables: { overrides: false } }; // Error


interface Unrelated { _?: any }

interface VariablesA { overrides?: OverridesInput; }
interface VariablesB { overrides?: OverridesInput; }

const foo2: Unrelated & { variables: VariablesA & VariablesB } = {
variables: {
overrides: false // Error
}
};

0 comments on commit 72a0f3b

Please sign in to comment.