From 5a6f4ee5b789b910e6b837ad5e9710c989987dc4 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 11 Jul 2023 09:58:22 -0700 Subject: [PATCH 1/2] Add test case for intersection/constraint bug fixed in 4.9 --- ...intersectionSatisfiesConstraint.errors.txt | 23 +++++++++ .../intersectionSatisfiesConstraint.js | 30 +++++++++++ .../intersectionSatisfiesConstraint.symbols | 50 +++++++++++++++++++ .../intersectionSatisfiesConstraint.types | 47 +++++++++++++++++ .../intersectionSatisfiesConstraint.ts | 18 +++++++ 5 files changed, 168 insertions(+) create mode 100644 tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt create mode 100644 tests/baselines/reference/intersectionSatisfiesConstraint.js create mode 100644 tests/baselines/reference/intersectionSatisfiesConstraint.symbols create mode 100644 tests/baselines/reference/intersectionSatisfiesConstraint.types create mode 100644 tests/cases/compiler/intersectionSatisfiesConstraint.ts diff --git a/tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt b/tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt new file mode 100644 index 0000000000000..ff0115e591e02 --- /dev/null +++ b/tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt @@ -0,0 +1,23 @@ +intersectionSatisfiesConstraint.ts(10,60): error TS2550: Property 'assign' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. + + +==== intersectionSatisfiesConstraint.ts (1 errors) ==== + interface FirstInterface { + commonProperty: number + } + + interface SecondInterface { + commonProperty: number + } + + const myFirstFunction = (param1: T) => { + const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) + ~~~~~~ +!!! error TS2550: Property 'assign' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. + mySecondFunction(newParam) + } + + const mySecondFunction = (newParam: T) => { + return newParam + } + \ No newline at end of file diff --git a/tests/baselines/reference/intersectionSatisfiesConstraint.js b/tests/baselines/reference/intersectionSatisfiesConstraint.js new file mode 100644 index 0000000000000..e0fcbc6e90944 --- /dev/null +++ b/tests/baselines/reference/intersectionSatisfiesConstraint.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] //// + +//// [intersectionSatisfiesConstraint.ts] +interface FirstInterface { + commonProperty: number +} + +interface SecondInterface { + commonProperty: number +} + +const myFirstFunction = (param1: T) => { + const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) + mySecondFunction(newParam) +} + +const mySecondFunction = (newParam: T) => { + return newParam +} + + +//// [intersectionSatisfiesConstraint.js] +"use strict"; +var myFirstFunction = function (param1) { + var newParam = Object.assign(param1, { otherProperty: 3 }); + mySecondFunction(newParam); +}; +var mySecondFunction = function (newParam) { + return newParam; +}; diff --git a/tests/baselines/reference/intersectionSatisfiesConstraint.symbols b/tests/baselines/reference/intersectionSatisfiesConstraint.symbols new file mode 100644 index 0000000000000..4da3eff895a67 --- /dev/null +++ b/tests/baselines/reference/intersectionSatisfiesConstraint.symbols @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] //// + +=== intersectionSatisfiesConstraint.ts === +interface FirstInterface { +>FirstInterface : Symbol(FirstInterface, Decl(intersectionSatisfiesConstraint.ts, 0, 0)) + + commonProperty: number +>commonProperty : Symbol(FirstInterface.commonProperty, Decl(intersectionSatisfiesConstraint.ts, 0, 26)) +} + +interface SecondInterface { +>SecondInterface : Symbol(SecondInterface, Decl(intersectionSatisfiesConstraint.ts, 2, 1)) + + commonProperty: number +>commonProperty : Symbol(SecondInterface.commonProperty, Decl(intersectionSatisfiesConstraint.ts, 4, 27)) +} + +const myFirstFunction = (param1: T) => { +>myFirstFunction : Symbol(myFirstFunction, Decl(intersectionSatisfiesConstraint.ts, 8, 5)) +>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 8, 25)) +>FirstInterface : Symbol(FirstInterface, Decl(intersectionSatisfiesConstraint.ts, 0, 0)) +>SecondInterface : Symbol(SecondInterface, Decl(intersectionSatisfiesConstraint.ts, 2, 1)) +>param1 : Symbol(param1, Decl(intersectionSatisfiesConstraint.ts, 8, 69)) +>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 8, 25)) + + const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) +>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 9, 9)) +>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 8, 25)) +>otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 9, 25)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>param1 : Symbol(param1, Decl(intersectionSatisfiesConstraint.ts, 8, 69)) +>otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 9, 75)) + + mySecondFunction(newParam) +>mySecondFunction : Symbol(mySecondFunction, Decl(intersectionSatisfiesConstraint.ts, 13, 5)) +>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 9, 9)) +} + +const mySecondFunction = (newParam: T) => { +>mySecondFunction : Symbol(mySecondFunction, Decl(intersectionSatisfiesConstraint.ts, 13, 5)) +>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 13, 26)) +>commonProperty : Symbol(commonProperty, Decl(intersectionSatisfiesConstraint.ts, 13, 37)) +>otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 13, 61)) +>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 13, 87)) +>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 13, 26)) + + return newParam +>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 13, 87)) +} + diff --git a/tests/baselines/reference/intersectionSatisfiesConstraint.types b/tests/baselines/reference/intersectionSatisfiesConstraint.types new file mode 100644 index 0000000000000..4bee6e7345780 --- /dev/null +++ b/tests/baselines/reference/intersectionSatisfiesConstraint.types @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] //// + +=== intersectionSatisfiesConstraint.ts === +interface FirstInterface { + commonProperty: number +>commonProperty : number +} + +interface SecondInterface { + commonProperty: number +>commonProperty : number +} + +const myFirstFunction = (param1: T) => { +>myFirstFunction : (param1: T) => void +>(param1: T) => { const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) mySecondFunction(newParam)} : (param1: T) => void +>param1 : T + + const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) +>newParam : T & { otherProperty: number; } +>otherProperty : number +>Object.assign(param1, { otherProperty: 3 }) : any +>Object.assign : any +>Object : ObjectConstructor +>assign : any +>param1 : FirstInterface | SecondInterface +>{ otherProperty: 3 } : { otherProperty: number; } +>otherProperty : number +>3 : 3 + + mySecondFunction(newParam) +>mySecondFunction(newParam) : { commonProperty: number; otherProperty: number; } +>mySecondFunction : (newParam: T) => T +>newParam : (FirstInterface | SecondInterface) & { otherProperty: number; } +} + +const mySecondFunction = (newParam: T) => { +>mySecondFunction : (newParam: T) => T +>(newParam: T) => { return newParam} : (newParam: T) => T +>commonProperty : number +>otherProperty : number +>newParam : T + + return newParam +>newParam : T +} + diff --git a/tests/cases/compiler/intersectionSatisfiesConstraint.ts b/tests/cases/compiler/intersectionSatisfiesConstraint.ts new file mode 100644 index 0000000000000..ef059154baa46 --- /dev/null +++ b/tests/cases/compiler/intersectionSatisfiesConstraint.ts @@ -0,0 +1,18 @@ +// @strict: true + +interface FirstInterface { + commonProperty: number +} + +interface SecondInterface { + commonProperty: number +} + +const myFirstFunction = (param1: T) => { + const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) + mySecondFunction(newParam) +} + +const mySecondFunction = (newParam: T) => { + return newParam +} From 7630a583f09279b599138cc91ea74972ade6eef1 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 13 Jul 2023 14:43:13 -0700 Subject: [PATCH 2/2] Make test not have errors --- ...intersectionSatisfiesConstraint.errors.txt | 23 ------------------- .../intersectionSatisfiesConstraint.symbols | 2 ++ .../intersectionSatisfiesConstraint.types | 8 +++---- .../intersectionSatisfiesConstraint.ts | 1 + 4 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt diff --git a/tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt b/tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt deleted file mode 100644 index ff0115e591e02..0000000000000 --- a/tests/baselines/reference/intersectionSatisfiesConstraint.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -intersectionSatisfiesConstraint.ts(10,60): error TS2550: Property 'assign' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. - - -==== intersectionSatisfiesConstraint.ts (1 errors) ==== - interface FirstInterface { - commonProperty: number - } - - interface SecondInterface { - commonProperty: number - } - - const myFirstFunction = (param1: T) => { - const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) - ~~~~~~ -!!! error TS2550: Property 'assign' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. - mySecondFunction(newParam) - } - - const mySecondFunction = (newParam: T) => { - return newParam - } - \ No newline at end of file diff --git a/tests/baselines/reference/intersectionSatisfiesConstraint.symbols b/tests/baselines/reference/intersectionSatisfiesConstraint.symbols index 4da3eff895a67..3c2153413c733 100644 --- a/tests/baselines/reference/intersectionSatisfiesConstraint.symbols +++ b/tests/baselines/reference/intersectionSatisfiesConstraint.symbols @@ -27,7 +27,9 @@ const myFirstFunction = (param1: T) >newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 9, 9)) >T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 8, 25)) >otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 9, 25)) +>Object.assign : Symbol(ObjectConstructor.assign, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>assign : Symbol(ObjectConstructor.assign, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >param1 : Symbol(param1, Decl(intersectionSatisfiesConstraint.ts, 8, 69)) >otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 9, 75)) diff --git a/tests/baselines/reference/intersectionSatisfiesConstraint.types b/tests/baselines/reference/intersectionSatisfiesConstraint.types index 4bee6e7345780..49e5eda86e073 100644 --- a/tests/baselines/reference/intersectionSatisfiesConstraint.types +++ b/tests/baselines/reference/intersectionSatisfiesConstraint.types @@ -19,11 +19,11 @@ const myFirstFunction = (param1: T) const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) >newParam : T & { otherProperty: number; } >otherProperty : number ->Object.assign(param1, { otherProperty: 3 }) : any ->Object.assign : any +>Object.assign(param1, { otherProperty: 3 }) : T & { otherProperty: number; } +>Object.assign : { (target: T, source: U): T & U; (target: T, source1: U, source2: V): T & U & V; (target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; } >Object : ObjectConstructor ->assign : any ->param1 : FirstInterface | SecondInterface +>assign : { (target: T, source: U): T & U; (target: T, source1: U, source2: V): T & U & V; (target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; } +>param1 : T >{ otherProperty: 3 } : { otherProperty: number; } >otherProperty : number >3 : 3 diff --git a/tests/cases/compiler/intersectionSatisfiesConstraint.ts b/tests/cases/compiler/intersectionSatisfiesConstraint.ts index ef059154baa46..69d76acc595cd 100644 --- a/tests/cases/compiler/intersectionSatisfiesConstraint.ts +++ b/tests/cases/compiler/intersectionSatisfiesConstraint.ts @@ -1,4 +1,5 @@ // @strict: true +// @lib: esnext interface FirstInterface { commonProperty: number