Skip to content

Commit ac0af46

Browse files
committed
Add test case from #30771
1 parent 667329d commit ac0af46

5 files changed

+187
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(13,35): error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'number | IProps'.
2+
Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.
3+
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(16,7): error TS2322: Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'number | IProps'.
4+
Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'IProps'.
5+
Types of property 'nestedProp' are incompatible.
6+
Type '{ asdfasdf: string; }' has no properties in common with type '{ testBool?: boolean; }'.
7+
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(19,56): error TS2326: Types of property 'nestedProps' are incompatible.
8+
Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'IProps'.
9+
Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.
10+
11+
12+
==== tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts (3 errors) ====
13+
interface IProps {
14+
iconProp?: string;
15+
nestedProp?: {
16+
testBool?: boolean;
17+
}
18+
}
19+
20+
interface INestedProps {
21+
nestedProps?: IProps;
22+
}
23+
24+
// These are the types of errors we want:
25+
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
!!! error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'number | IProps'.
28+
!!! error TS2322: Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.
29+
30+
// Nested typing works here and we also get an expected error:
31+
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
32+
~~~~~~
33+
!!! error TS2322: Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'number | IProps'.
34+
!!! error TS2322: Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'IProps'.
35+
!!! error TS2322: Types of property 'nestedProp' are incompatible.
36+
!!! error TS2322: Type '{ asdfasdf: string; }' has no properties in common with type '{ testBool?: boolean; }'.
37+
38+
// Want an error generated here but there isn't one.
39+
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
40+
~~~~~~~~~~~~~~~~~~~~~~~~~~
41+
!!! error TS2326: Types of property 'nestedProps' are incompatible.
42+
!!! error TS2326: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'IProps'.
43+
!!! error TS2326: Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.
44+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//// [nonObjectUnionNestedExcessPropertyCheck.ts]
2+
interface IProps {
3+
iconProp?: string;
4+
nestedProp?: {
5+
testBool?: boolean;
6+
}
7+
}
8+
9+
interface INestedProps {
10+
nestedProps?: IProps;
11+
}
12+
13+
// These are the types of errors we want:
14+
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
15+
16+
// Nested typing works here and we also get an expected error:
17+
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
18+
19+
// Want an error generated here but there isn't one.
20+
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
21+
22+
23+
//// [nonObjectUnionNestedExcessPropertyCheck.js]
24+
// These are the types of errors we want:
25+
var propB1 = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
26+
// Nested typing works here and we also get an expected error:
27+
var propB2 = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
28+
// Want an error generated here but there isn't one.
29+
var propA1 = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
=== tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts ===
2+
interface IProps {
3+
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))
4+
5+
iconProp?: string;
6+
>iconProp : Symbol(IProps.iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 18))
7+
8+
nestedProp?: {
9+
>nestedProp : Symbol(IProps.nestedProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 1, 22))
10+
11+
testBool?: boolean;
12+
>testBool : Symbol(testBool, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 2, 18))
13+
}
14+
}
15+
16+
interface INestedProps {
17+
>INestedProps : Symbol(INestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 5, 1))
18+
19+
nestedProps?: IProps;
20+
>nestedProps : Symbol(INestedProps.nestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 7, 24))
21+
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))
22+
}
23+
24+
// These are the types of errors we want:
25+
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
26+
>propB1 : Symbol(propB1, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 12, 5))
27+
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))
28+
>INVALID_PROP_NAME : Symbol(INVALID_PROP_NAME, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 12, 33))
29+
>iconProp : Symbol(iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 12, 61))
30+
31+
// Nested typing works here and we also get an expected error:
32+
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
33+
>propB2 : Symbol(propB2, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 5))
34+
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))
35+
>nestedProp : Symbol(nestedProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 33))
36+
>asdfasdf : Symbol(asdfasdf, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 47))
37+
>iconProp : Symbol(iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 67))
38+
39+
// Want an error generated here but there isn't one.
40+
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
41+
>propA1 : Symbol(propA1, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 5))
42+
>INestedProps : Symbol(INestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 5, 1))
43+
>nestedProps : Symbol(nestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 39))
44+
>INVALID_PROP_NAME : Symbol(INVALID_PROP_NAME, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 54))
45+
>iconProp : Symbol(iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 82))
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
=== tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts ===
2+
interface IProps {
3+
iconProp?: string;
4+
>iconProp : string
5+
6+
nestedProp?: {
7+
>nestedProp : { testBool?: boolean; }
8+
9+
testBool?: boolean;
10+
>testBool : boolean
11+
}
12+
}
13+
14+
interface INestedProps {
15+
nestedProps?: IProps;
16+
>nestedProps : IProps
17+
}
18+
19+
// These are the types of errors we want:
20+
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
21+
>propB1 : number | IProps
22+
>{ INVALID_PROP_NAME: 'share', iconProp: 'test' } : { INVALID_PROP_NAME: string; iconProp: string; }
23+
>INVALID_PROP_NAME : string
24+
>'share' : "share"
25+
>iconProp : string
26+
>'test' : "test"
27+
28+
// Nested typing works here and we also get an expected error:
29+
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
30+
>propB2 : number | IProps
31+
>{ nestedProp: { asdfasdf: 'test' }, iconProp: 'test' } : { nestedProp: { asdfasdf: string; }; iconProp: string; }
32+
>nestedProp : { asdfasdf: string; }
33+
>{ asdfasdf: 'test' } : { asdfasdf: string; }
34+
>asdfasdf : string
35+
>'test' : "test"
36+
>iconProp : string
37+
>'test' : "test"
38+
39+
// Want an error generated here but there isn't one.
40+
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
41+
>propA1 : number | INestedProps
42+
>{ nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } } : { nestedProps: { INVALID_PROP_NAME: string; iconProp: string; }; }
43+
>nestedProps : { INVALID_PROP_NAME: string; iconProp: string; }
44+
>{ INVALID_PROP_NAME: 'share', iconProp: 'test' } : { INVALID_PROP_NAME: string; iconProp: string; }
45+
>INVALID_PROP_NAME : string
46+
>'share' : "share"
47+
>iconProp : string
48+
>'test' : "test"
49+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
interface IProps {
2+
iconProp?: string;
3+
nestedProp?: {
4+
testBool?: boolean;
5+
}
6+
}
7+
8+
interface INestedProps {
9+
nestedProps?: IProps;
10+
}
11+
12+
// These are the types of errors we want:
13+
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
14+
15+
// Nested typing works here and we also get an expected error:
16+
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
17+
18+
// Want an error generated here but there isn't one.
19+
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };

0 commit comments

Comments
 (0)