-
-
Notifications
You must be signed in to change notification settings - Fork 391
Open
Description
I got some code for parsing command line flags/user inputs that commonly uses patterns like this
---@return string ...
local function strsplit(str, sep) end
local a, b, c = strsplit(userinput, ",")
b = tonumber(b) or 0 -- error: This variable is defined as type `string`. Cannot convert its type to `number`
The fix is to define b as string|number in the declaration, but it's a bit cumbersome, especially if I just want b as a number:
local a,
---@type number|string
b, c = strsplit(userinput, ",")
So it would be nice if common type conversion patterns like this could be recognized automatically and either allow the cast or infer the type as string|number from the beginning.
Edit: See comment below, the implicit cast is already happening, this is really about type inference based on later assignments. Which may or may not be a good idea.
Metadata
Metadata
Assignees
Labels
No labels