Closed
Description
TypeScript Version: 3.9.2
Search Terms: Regression, merge types
Code
type Merge<T, S> = Omit<T, Extract<keyof T, keyof S>> & S;
type WithNumberId = {
_id: number,
otherKey?: number,
};
type WithStringId = {
_id: string,
otherKey?: string,
};
function convertToStringId<T extends WithNumberId>(data: T): Merge<T, WithStringId> {
const convertedData: Merge<T, WithStringId> = {
...data,
_id: data._id.toString(),
};
if (data.otherKey) {
convertedData.otherKey = data.otherKey.toString();
}
return convertedData;
}
Expected behavior: No error (3.8x is fine)
Actual behavior: Definition of const convertedData
gives error
Related Issues: Maybe #38460