Search
Star
Feedback
Setup for Free
© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Typescript behaving strangely when inferring function return type - Theo's Typesafe Cult
TTC
Theo's Typesafe Cult
•
4y ago
•
3 replies
soydev
Typescript behaving strangely when inferring function return type
Today I stumbled across a thing in typescript
, where it was inferring the return type of a function with an if statement very strangely
Playgroundlink
:
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMOcBGBDATgCkwLwC5EwQBbNAUywEpiBvRA40i6xAX0QB9F6v6AKESIA9KJGSRAPQD8wxDGCI8GfDT4KRWSlBBYk9AhwUntu-YZMnBoSLARNsBHCjgtyVWppHipiOQUlFTcNISkdPQM+NzNOBUjLPmsgA
Why is ts inferring the return type as
{foo?: undefined}
{foo?: undefined}
when its just
{}
{}
? When I type the return value explicitly it just does what you would expect it to do
.
.
.
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way
.
Theo's Typesafe Cult
Join
26,564
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Recent Announcements
Similar Threads
Was this page helpful?
Yes
No
Similar Threads
toZod package - Inferring schema from return type
TTC
Theo's Typesafe Cult / questions
4y ago
Why typescript type inference is behaving like this?
TTC
Theo's Typesafe Cult / questions
4y ago
trpc useQuery/useMutation not inferring return type of prisma query
TTC
Theo's Typesafe Cult / questions
2y ago