Transfer practice · labelOrFallback(value: unknown): string preserves a string, including empty text, and returns "Unnamed" for other types.
v3 · Activity 1 of 1 · types · refinement · 12 min Runs here
Use a familiar idea in a different task. Read the changed requirement before running.
labelOrFallback(value: unknown): string preserves a string, including empty text, and returns "Unnamed" for other types.
Interface: doubleNumber(value:unknown) -> number
| Input | Expected |
|---|---|
Text"Lamp" | "Lamp" |
Empty text"" | "" |
Number is not a label5 | "Unnamed" |
local function usableCount(value: unknown): number
if type(value) == "number" then
return math.max(0, value)
end
return 0
end
return usableCountThe type check makes the numeric operation meaningful. The fallback handles strings, booleans and nil.
New syntax: : unknown, : number, type refinement
Luau annotations such as value: number describe intended types for static analysis. They are not runtime permission checks and do not convert a string into a number.
A value typed unknown must be checked before you use it as a specific type. if type(value) == "number" then narrows it inside that branch.
This activity returns twice a numeric input and zero for other types. A standalone runtime compiles annotations, but this editor does not claim the full Roblox Studio type checker or autocomplete.
Select a word or symbol in this authored example. Your editor draft stays unchanged.
doubleNumbervalue: unknown: number
value 2
doubleNumberThis is a private experiment copy. It does not replace your answer or complete the activity.
These inputs apply when your scratchpad returns the function described by the activity interface.
Your output will appear here.
Replace this code with the starter? Download your draft to keep a copy.
Your output will appear here.
Sign in with RoCreators to save private progress across devices. Community verification is separate.