* Fix #33732

* Remove code change but keep test
This commit is contained in:
Jack Williams
2020-03-17 21:58:52 +00:00
committed by GitHub
parent 66aa9e77bf
commit c600aa7411
5 changed files with 286 additions and 0 deletions

View File

@@ -192,4 +192,43 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(114,63): error TS2322: Typ
const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Error
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
// Repro from #33732
interface I1 {
prop1: string;
}
interface I2 {
prop2: string;
}
interface I3 extends Record<string, string> {
}
type Properties =
| { [key: string]: never }
| I1
| I2
| I3
;
declare const prop1: string;
declare const prop2: string | undefined;
function F1(_arg: { props: Properties }) { }
F1({
props: {
prop1,
prop2,
},
});
function F2(_props: Properties) { }
F2({
prop1,
prop2,
});

View File

@@ -113,6 +113,45 @@ const dataSpecification: ObjectDataSpecification = { // Error
const obj1: { [x: string]: number } | { [x: number]: number } = { a: 'abc' }; // Error
const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Error
// Repro from #33732
interface I1 {
prop1: string;
}
interface I2 {
prop2: string;
}
interface I3 extends Record<string, string> {
}
type Properties =
| { [key: string]: never }
| I1
| I2
| I3
;
declare const prop1: string;
declare const prop2: string | undefined;
function F1(_arg: { props: Properties }) { }
F1({
props: {
prop1,
prop2,
},
});
function F2(_props: Properties) { }
F2({
prop1,
prop2,
});
//// [excessPropertyCheckWithUnions.js]
@@ -177,3 +216,15 @@ var dataSpecification = {
// Repro from #34611
var obj1 = { a: 'abc' }; // Error
var obj2 = { a: 5, c: 'abc' }; // Error
function F1(_arg) { }
F1({
props: {
prop1: prop1,
prop2: prop2
}
});
function F2(_props) { }
F2({
prop1: prop1,
prop2: prop2
});

View File

@@ -310,3 +310,86 @@ const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Er
>a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 113, 55))
>c : Symbol(c, Decl(excessPropertyCheckWithUnions.ts, 113, 61))
// Repro from #33732
interface I1 {
>I1 : Symbol(I1, Decl(excessPropertyCheckWithUnions.ts, 113, 73))
prop1: string;
>prop1 : Symbol(I1.prop1, Decl(excessPropertyCheckWithUnions.ts, 117, 14))
}
interface I2 {
>I2 : Symbol(I2, Decl(excessPropertyCheckWithUnions.ts, 119, 1))
prop2: string;
>prop2 : Symbol(I2.prop2, Decl(excessPropertyCheckWithUnions.ts, 121, 14))
}
interface I3 extends Record<string, string> {
>I3 : Symbol(I3, Decl(excessPropertyCheckWithUnions.ts, 123, 1))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
}
type Properties =
>Properties : Symbol(Properties, Decl(excessPropertyCheckWithUnions.ts, 127, 1))
| { [key: string]: never }
>key : Symbol(key, Decl(excessPropertyCheckWithUnions.ts, 130, 9))
| I1
>I1 : Symbol(I1, Decl(excessPropertyCheckWithUnions.ts, 113, 73))
| I2
>I2 : Symbol(I2, Decl(excessPropertyCheckWithUnions.ts, 119, 1))
| I3
>I3 : Symbol(I3, Decl(excessPropertyCheckWithUnions.ts, 123, 1))
;
declare const prop1: string;
>prop1 : Symbol(prop1, Decl(excessPropertyCheckWithUnions.ts, 137, 13))
declare const prop2: string | undefined;
>prop2 : Symbol(prop2, Decl(excessPropertyCheckWithUnions.ts, 138, 13))
function F1(_arg: { props: Properties }) { }
>F1 : Symbol(F1, Decl(excessPropertyCheckWithUnions.ts, 138, 40))
>_arg : Symbol(_arg, Decl(excessPropertyCheckWithUnions.ts, 140, 12))
>props : Symbol(props, Decl(excessPropertyCheckWithUnions.ts, 140, 19))
>Properties : Symbol(Properties, Decl(excessPropertyCheckWithUnions.ts, 127, 1))
F1({
>F1 : Symbol(F1, Decl(excessPropertyCheckWithUnions.ts, 138, 40))
props: {
>props : Symbol(props, Decl(excessPropertyCheckWithUnions.ts, 141, 4))
prop1,
>prop1 : Symbol(prop1, Decl(excessPropertyCheckWithUnions.ts, 142, 12))
prop2,
>prop2 : Symbol(prop2, Decl(excessPropertyCheckWithUnions.ts, 143, 14))
},
});
function F2(_props: Properties) { }
>F2 : Symbol(F2, Decl(excessPropertyCheckWithUnions.ts, 146, 3))
>_props : Symbol(_props, Decl(excessPropertyCheckWithUnions.ts, 148, 12))
>Properties : Symbol(Properties, Decl(excessPropertyCheckWithUnions.ts, 127, 1))
F2({
>F2 : Symbol(F2, Decl(excessPropertyCheckWithUnions.ts, 146, 3))
prop1,
>prop1 : Symbol(prop1, Decl(excessPropertyCheckWithUnions.ts, 149, 4))
prop2,
>prop2 : Symbol(prop2, Decl(excessPropertyCheckWithUnions.ts, 150, 10))
});

View File

@@ -364,3 +364,77 @@ const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Er
>c : string
>'abc' : "abc"
// Repro from #33732
interface I1 {
prop1: string;
>prop1 : string
}
interface I2 {
prop2: string;
>prop2 : string
}
interface I3 extends Record<string, string> {
}
type Properties =
>Properties : Properties
| { [key: string]: never }
>key : string
| I1
| I2
| I3
;
declare const prop1: string;
>prop1 : string
declare const prop2: string | undefined;
>prop2 : string | undefined
function F1(_arg: { props: Properties }) { }
>F1 : (_arg: { props: Properties; }) => void
>_arg : { props: Properties; }
>props : Properties
F1({
>F1({ props: { prop1, prop2, },}) : void
>F1 : (_arg: { props: Properties; }) => void
>{ props: { prop1, prop2, },} : { props: { prop1: string; prop2: string | undefined; }; }
props: {
>props : { prop1: string; prop2: string | undefined; }
>{ prop1, prop2, } : { prop1: string; prop2: string | undefined; }
prop1,
>prop1 : string
prop2,
>prop2 : string | undefined
},
});
function F2(_props: Properties) { }
>F2 : (_props: Properties) => void
>_props : Properties
F2({
>F2({ prop1, prop2,}) : void
>F2 : (_props: Properties) => void
>{ prop1, prop2,} : { prop1: string; prop2: string | undefined; }
prop1,
>prop1 : string
prop2,
>prop2 : string | undefined
});

View File

@@ -113,3 +113,42 @@ const dataSpecification: ObjectDataSpecification = { // Error
const obj1: { [x: string]: number } | { [x: number]: number } = { a: 'abc' }; // Error
const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Error
// Repro from #33732
interface I1 {
prop1: string;
}
interface I2 {
prop2: string;
}
interface I3 extends Record<string, string> {
}
type Properties =
| { [key: string]: never }
| I1
| I2
| I3
;
declare const prop1: string;
declare const prop2: string | undefined;
function F1(_arg: { props: Properties }) { }
F1({
props: {
prop1,
prop2,
},
});
function F2(_props: Properties) { }
F2({
prop1,
prop2,
});