Skip to content

Commit

Permalink
Add test case from #30771
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Apr 10, 2019
1 parent 667329d commit ac0af46
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(13,35): error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'number | IProps'.
Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(16,7): error TS2322: Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'number | IProps'.
Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'IProps'.
Types of property 'nestedProp' are incompatible.
Type '{ asdfasdf: string; }' has no properties in common with type '{ testBool?: boolean; }'.
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(19,56): error TS2326: Types of property 'nestedProps' are incompatible.
Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'IProps'.
Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.


==== tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts (3 errors) ====
interface IProps {
iconProp?: string;
nestedProp?: {
testBool?: boolean;
}
}

interface INestedProps {
nestedProps?: IProps;
}

// These are the types of errors we want:
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'number | IProps'.
!!! error TS2322: Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.

// Nested typing works here and we also get an expected error:
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
~~~~~~
!!! error TS2322: Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'number | IProps'.
!!! error TS2322: Type '{ nestedProp: { asdfasdf: string; }; iconProp: string; }' is not assignable to type 'IProps'.
!!! error TS2322: Types of property 'nestedProp' are incompatible.
!!! error TS2322: Type '{ asdfasdf: string; }' has no properties in common with type '{ testBool?: boolean; }'.

// Want an error generated here but there isn't one.
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2326: Types of property 'nestedProps' are incompatible.
!!! error TS2326: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'IProps'.
!!! error TS2326: Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [nonObjectUnionNestedExcessPropertyCheck.ts]
interface IProps {
iconProp?: string;
nestedProp?: {
testBool?: boolean;
}
}

interface INestedProps {
nestedProps?: IProps;
}

// These are the types of errors we want:
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };

// Nested typing works here and we also get an expected error:
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };

// Want an error generated here but there isn't one.
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };


//// [nonObjectUnionNestedExcessPropertyCheck.js]
// These are the types of errors we want:
var propB1 = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
// Nested typing works here and we also get an expected error:
var propB2 = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
// Want an error generated here but there isn't one.
var propA1 = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
=== tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts ===
interface IProps {
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))

iconProp?: string;
>iconProp : Symbol(IProps.iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 18))

nestedProp?: {
>nestedProp : Symbol(IProps.nestedProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 1, 22))

testBool?: boolean;
>testBool : Symbol(testBool, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 2, 18))
}
}

interface INestedProps {
>INestedProps : Symbol(INestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 5, 1))

nestedProps?: IProps;
>nestedProps : Symbol(INestedProps.nestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 7, 24))
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))
}

// These are the types of errors we want:
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
>propB1 : Symbol(propB1, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 12, 5))
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))
>INVALID_PROP_NAME : Symbol(INVALID_PROP_NAME, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 12, 33))
>iconProp : Symbol(iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 12, 61))

// Nested typing works here and we also get an expected error:
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
>propB2 : Symbol(propB2, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 5))
>IProps : Symbol(IProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 0, 0))
>nestedProp : Symbol(nestedProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 33))
>asdfasdf : Symbol(asdfasdf, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 47))
>iconProp : Symbol(iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 15, 67))

// Want an error generated here but there isn't one.
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
>propA1 : Symbol(propA1, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 5))
>INestedProps : Symbol(INestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 5, 1))
>nestedProps : Symbol(nestedProps, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 39))
>INVALID_PROP_NAME : Symbol(INVALID_PROP_NAME, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 54))
>iconProp : Symbol(iconProp, Decl(nonObjectUnionNestedExcessPropertyCheck.ts, 18, 82))

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
=== tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts ===
interface IProps {
iconProp?: string;
>iconProp : string

nestedProp?: {
>nestedProp : { testBool?: boolean; }

testBool?: boolean;
>testBool : boolean
}
}

interface INestedProps {
nestedProps?: IProps;
>nestedProps : IProps
}

// These are the types of errors we want:
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
>propB1 : number | IProps
>{ INVALID_PROP_NAME: 'share', iconProp: 'test' } : { INVALID_PROP_NAME: string; iconProp: string; }
>INVALID_PROP_NAME : string
>'share' : "share"
>iconProp : string
>'test' : "test"

// Nested typing works here and we also get an expected error:
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
>propB2 : number | IProps
>{ nestedProp: { asdfasdf: 'test' }, iconProp: 'test' } : { nestedProp: { asdfasdf: string; }; iconProp: string; }
>nestedProp : { asdfasdf: string; }
>{ asdfasdf: 'test' } : { asdfasdf: string; }
>asdfasdf : string
>'test' : "test"
>iconProp : string
>'test' : "test"

// Want an error generated here but there isn't one.
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
>propA1 : number | INestedProps
>{ nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } } : { nestedProps: { INVALID_PROP_NAME: string; iconProp: string; }; }
>nestedProps : { INVALID_PROP_NAME: string; iconProp: string; }
>{ INVALID_PROP_NAME: 'share', iconProp: 'test' } : { INVALID_PROP_NAME: string; iconProp: string; }
>INVALID_PROP_NAME : string
>'share' : "share"
>iconProp : string
>'test' : "test"

19 changes: 19 additions & 0 deletions tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
interface IProps {
iconProp?: string;
nestedProp?: {
testBool?: boolean;
}
}

interface INestedProps {
nestedProps?: IProps;
}

// These are the types of errors we want:
const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };

// Nested typing works here and we also get an expected error:
const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };

// Want an error generated here but there isn't one.
const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };

0 comments on commit ac0af46

Please sign in to comment.