I just got around to trying to convert my code from FastSpawn to task.spawn
As it stands, the typings of task.spawn
makes is near-unusuable without ugly-looking code. Why?
Well… currently the following code yields two script analysis warnings:
--!strict
task.spawn(function()
print('Hello, World!')
end)
This typing is bad because it assumes that the argument you pass into task.spawn has to return something. So at very least the any
being returned should be optional.
The following monkey code with modified typing works:
--!strict
local task_spawn = task.spawn :: (((any) -> any?) | thread) -> any
task_spawn(function()
print('Hello, World!')
end)
That’s one problem solved—however, the argument(s) passed into task.spawn are also not variadic or optional. So you always have to pass a second argument to the task.spawn… even if you don’t want to
--!strict
task.spawn(function()
print('Hello, World!')
end :: any)
You could pass nil here, however this does affect the tuple size.
This is currently the way I am using task.spawn
, and it’s super ugly:
--!strict
(task.spawn :: any)(function()
print('Hello, World!')
end)
HOWEVER, if I have anything before that line, I need to prepend the spawn line, or append the previous line, with a semicolon to avoid a syntax error:
--!strict
print("Hello?")
;(task.spawn :: any)(function()
print('Hello, World!')
end)
--!strict
print("Hello?");
(task.spawn :: any)(function()
print('Hello, World!')
end)
Please see if you can fix these typings. I’m stuck with some really ugly looking code.