From ac0af46684a4e3b8da660474f57bbce96e282a7c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 10 Apr 2019 16:44:45 -0700 Subject: [PATCH] Add test case from #30771 --- ...tUnionNestedExcessPropertyCheck.errors.txt | 44 +++++++++++++++++ ...nonObjectUnionNestedExcessPropertyCheck.js | 29 +++++++++++ ...jectUnionNestedExcessPropertyCheck.symbols | 46 +++++++++++++++++ ...ObjectUnionNestedExcessPropertyCheck.types | 49 +++++++++++++++++++ ...nonObjectUnionNestedExcessPropertyCheck.ts | 19 +++++++ 5 files changed, 187 insertions(+) create mode 100644 tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.errors.txt create mode 100644 tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.js create mode 100644 tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.symbols create mode 100644 tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.types create mode 100644 tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts diff --git a/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.errors.txt b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.errors.txt new file mode 100644 index 0000000000000..4cf8a99e0eafb --- /dev/null +++ b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.errors.txt @@ -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'. + \ No newline at end of file diff --git a/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.js b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.js new file mode 100644 index 0000000000000..b286049e4a450 --- /dev/null +++ b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.js @@ -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' } }; diff --git a/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.symbols b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.symbols new file mode 100644 index 0000000000000..95e6c33a64e0f --- /dev/null +++ b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.symbols @@ -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)) + diff --git a/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.types b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.types new file mode 100644 index 0000000000000..3e05dbd362853 --- /dev/null +++ b/tests/baselines/reference/nonObjectUnionNestedExcessPropertyCheck.types @@ -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" + diff --git a/tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts b/tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts new file mode 100644 index 0000000000000..5050d33c05eb4 --- /dev/null +++ b/tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts @@ -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' } };