Skip to content

Fix #33732 #36077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

51 changes: 51 additions & 0 deletions tests/baselines/reference/excessPropertyCheckWithUnions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
});
83 changes: 83 additions & 0 deletions tests/baselines/reference/excessPropertyCheckWithUnions.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

});

74 changes: 74 additions & 0 deletions tests/baselines/reference/excessPropertyCheckWithUnions.types
Original file line number Diff line number Diff line change
Expand Up @@ -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

});

39 changes: 39 additions & 0 deletions tests/cases/compiler/excessPropertyCheckWithUnions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});