You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature request] User defined type guards like TypeScript's one #2476
As a simple example, I would like to annotate the following @guard x string. This is in effect returning a boolean, which narrows down the type of the argument x.
---@paramxunknown---@guard x stringlocalfunctionisString(x)
returntype(x) =="string"end---@paramxstring | numberlocalfunctionmain(x)
ifisString(x) then-- x is stringprint(x)
else-- x is numberprint(x)
endend
Activity
firas-assaad commentedon Jan 12, 2024
I'd like this feature as well. It's been proposed a couple of times in the past, but it's apparently hard to implement: #1030 (comment)
itsDesignFlaw commentedon Jan 28, 2026
2 years later, is there any chance of getting this?
CppCXY commentedon Jan 28, 2026
emmyluals support this like: