-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
TypeScript Version: 2.9
Search Terms: Type intersection, type union, generics
Code
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
}
Expected behavior:
We should be able to pass newParam
to mySecondFunction
because FirstInterface
& SecondInterface
have commonProperty
in common.
Actual behavior:
Argument of type 'T & { otherProperty: number; }' is not assignable to parameter of type '{ commonProperty: number; otherProperty: number; }'.
MrCalen, carloslfu and arnauorriols
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript