So i made a Previous post about type checking and i was wrong at some points im not here to discuss this today but to tell you about my new founding.

so i figure this out by mistake but apperently if you make a function & function it will create this when you try and index it:
<1/2> Foo(Arg)->()

I tried to upload a photo but did not work :frowning: i hope you understand what i mean by that if not then:
You see some functions have 1 argument but different let me show you.

--If this arg 1 is number it will return number
--else arg 1 is boolean it will return boolean

function Foo(arg)
if (type(arg)=="number") then
return (arg == 1) and 1 or 0
elseif (arg == "boolean") then
return not arg

print(Foo(1)) --prints 0
print(Foo(false)) -- prints true


You may say so what?
Well when you index the function a gray ui appears showing you the Name of the
Function comments and details of the function in roblox studio.
If you just leave it so it will show you:
if you use a common typechecking and set the arg to (number|boolean)
then you get:

But how does roblox or native function have the fancy text details why their functions
can be commented like that and we cannot comment ours?
Good question i don’t know but i know this

function Foo(arg)
	if (type(arg) == "number") then
		return (arg == 1) and 1 or 0
	elseif (type(arg) == "boolean") then
		return not arg

local Foo = Foo :: ((arg:number)->number)&(boolean)->(boolean)

Now if you index Foo it will have the Secret technique
<1/2> Foo(arg:number):number
and if you click any of those buttons
<2/2> Foo(arg:boolean):boolean

So why did i post this?
Why is there stuff like this who are not documented anywhere in both luau documentation and roblox documentation?

And how much more secrets are there that we have not uncovered.
Or mabey im just a rookie and its common knowlage
if anyone knows how to comment on your functions properly and document them
please tell me i don’t know how!

what i mean is this
in javascript they use
/**@Param … Arg1*/
in lua they use
@Param … Arg1
thats the issue that im trying to solve.

You have reached the end thank you!


before any geek trying to correct me

function Foo(arg)
if (type(arg)=="number") then
return (arg == 1) and 1 or 0
elseif (type(arg) == "boolean") then
return not arg

This is documented. It’s called type inference and type refinement.


can you give the source link if you have it i searched for a long time but never found anything about it.

So i checked the web again and it was called subtyping in the luau official documentation so i guess i didn’t did that kind of big discovery after all.

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