mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 21:37:41 -06:00
Add test case for intersection/constraint bug fixed in 4.9 (#54972)
This commit is contained in:
parent
c468960578
commit
8a85b2aafb
30
tests/baselines/reference/intersectionSatisfiesConstraint.js
Normal file
30
tests/baselines/reference/intersectionSatisfiesConstraint.js
Normal file
@ -0,0 +1,30 @@
|
||||
//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] ////
|
||||
|
||||
//// [intersectionSatisfiesConstraint.ts]
|
||||
interface FirstInterface {
|
||||
commonProperty: number
|
||||
}
|
||||
|
||||
interface SecondInterface {
|
||||
commonProperty: number
|
||||
}
|
||||
|
||||
const myFirstFunction = <T extends FirstInterface | SecondInterface>(param1: T) => {
|
||||
const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 })
|
||||
mySecondFunction(newParam)
|
||||
}
|
||||
|
||||
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(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;
|
||||
};
|
||||
@ -0,0 +1,52 @@
|
||||
//// [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 = <T extends FirstInterface | SecondInterface>(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.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))
|
||||
|
||||
mySecondFunction(newParam)
|
||||
>mySecondFunction : Symbol(mySecondFunction, Decl(intersectionSatisfiesConstraint.ts, 13, 5))
|
||||
>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 9, 9))
|
||||
}
|
||||
|
||||
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(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))
|
||||
}
|
||||
|
||||
@ -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 = <T extends FirstInterface | SecondInterface>(param1: T) => {
|
||||
>myFirstFunction : <T extends FirstInterface | SecondInterface>(param1: T) => void
|
||||
><T extends FirstInterface | SecondInterface>(param1: T) => { const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) mySecondFunction(newParam)} : <T extends FirstInterface | SecondInterface>(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 }) : T & { otherProperty: number; }
|
||||
>Object.assign : { <T extends {}, U>(target: T, source: U): T & U; <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V; <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
|
||||
>Object : ObjectConstructor
|
||||
>assign : { <T extends {}, U>(target: T, source: U): T & U; <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V; <T extends {}, U, V, W>(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
|
||||
|
||||
mySecondFunction(newParam)
|
||||
>mySecondFunction(newParam) : { commonProperty: number; otherProperty: number; }
|
||||
>mySecondFunction : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
|
||||
>newParam : (FirstInterface | SecondInterface) & { otherProperty: number; }
|
||||
}
|
||||
|
||||
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(newParam: T) => {
|
||||
>mySecondFunction : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
|
||||
><T extends { commonProperty: number, otherProperty: number }>(newParam: T) => { return newParam} : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
|
||||
>commonProperty : number
|
||||
>otherProperty : number
|
||||
>newParam : T
|
||||
|
||||
return newParam
|
||||
>newParam : T
|
||||
}
|
||||
|
||||
19
tests/cases/compiler/intersectionSatisfiesConstraint.ts
Normal file
19
tests/cases/compiler/intersectionSatisfiesConstraint.ts
Normal file
@ -0,0 +1,19 @@
|
||||
// @strict: true
|
||||
// @lib: esnext
|
||||
|
||||
interface FirstInterface {
|
||||
commonProperty: number
|
||||
}
|
||||
|
||||
interface SecondInterface {
|
||||
commonProperty: number
|
||||
}
|
||||
|
||||
const myFirstFunction = <T extends FirstInterface | SecondInterface>(param1: T) => {
|
||||
const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 })
|
||||
mySecondFunction(newParam)
|
||||
}
|
||||
|
||||
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(newParam: T) => {
|
||||
return newParam
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user