-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
inline inference, function return type, as const
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
π» Code
const fn1 = () => Math.random() > 0 ? ({ a: '1' } as const) : { b: 'b' }
const fn2 = () => {
const objectAsConst = ({ a: '1' } as const)
return Math.random() > 0 ? objectAsConst : { b: 'b' };
}
π Actual behavior
Return type for fn1
is
{
readonly a: "1";
b?: undefined;
} | {
b: string;
readonly a?: undefined;
}
while for fn2
is
{
readonly a: "1";
} | {
b: string;
}
π Expected behavior
Return type for both functions should be
{
readonly a: "1";
} | {
b: string;
}
Inlining object should not change type of function
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created