What in the name of all that is holy is a "never"!?

Dear Colleagues,

I’ve never seen this type before in my time as a developer on roblox.
Even the roblox docs don’t mention it existing whatsoever.

I was just writing some pseudocode for another post I was making and stumbled upon this.

never

Does anyone know what this is? Maybe just a weird leftover or bug of some sort?


Best regards,
Pinker

1 Like

All a never is is a value that’s never expected to occur, it can’t occur. It’s impossible. All it is is a way for the type checker to infer this.

local var = "hello"

if type(var) == "string" and type(var) == "number" then
    --although not shown, var is now inferred as never.
    --this is because this code path is impossible. A variable can't be a string and a number at the same time.
end

You can use it to indicate certain things like a function never returning:

local function foo(): never
    --indicate never because this will loop indefinitely
    while true do
    end
end
2 Likes

I didin’t think I’d actually get a solution for this. It just sounded so ridiculous, I thought someone might’ve left a comment as a type by mistake.

Thanks for your answer!


Best regards,
Pinker

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.