How typing works of Instance.new() function?

How is the Instance.new() function typed? For example, when you type ‘Part’ as the argument, you get autocomplete suggestions for the Part class. I need to implement something similar for my own constructor

I need like this:

type musket = {
 Fire: (self: musket) -> (),
 Reload: (self: musket) -> (),
}

type sword = {
 Attack: (self: sword) -> (),
 Block: (self: sword) -> ()
}

function contructor(class: string): any
 -- code
end

contructor('musket') --> musket class
contructor('sword') --> sword class

Not too well versed in intellisense, but I think you can use the | (or) operator to define both types

function contructor(class: musket|sword): any
 -- code
end
2 Likes

This isn’t possible with the current type checking features. You have to manually assign the type each time.

2 Likes

as the person above said, this is not possible. At most, you can type a function into something like sword|musket|nil.

1 Like

You aren’t able to add types that can do this. It must be an internal thing that we cannot use. Would be great, though!

2 Likes

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