Type Checking Methods

Hey everyone. This may be a simple question to answer, however, I couldn’t find any articles online that helped with this.

I am fairly new to using the typeof function, and I find it extremely useful. The question I have is, how would you use typeof without calling a method on a class (module script)? I can say typeof(class.new()), and it solves the type issue I am having, however, I don’t want to call said function.

Any answers are appreciated; thank you in advance.

local class = {}
class.__index = class
local databases: {[string]: typeof(class.new)} = {}

It does not call the function at runtime.

1 Like

Does it not? Probably should have tested that before making this post. Sorry for wasting your time. Thank you so much for your quick response.

Nah it doesn’t, any type checking-related syntax is discarded when the code is compiled.

There is one known exception, that is when using a type assertion on a multi-value return, but in most cases people aren’t running into that.

1 Like