Exclude other types from type in luau type check

I have written a custom instance module.

If I put (workspace.aNpc) into the constructor function of the module,
Returns a custom instance, and its type is (workspace.aNpc)'s type containing some custom properties, methods, and events.

e.g.

function module.new<object>(object:object):
	{isDead:bool, toBinaryCode:()->str, died:goodSignal} & object

	local self = setmetatable({},customInstance)
	--some codes
	return self
end

However, I want some specific events or features of the original Instance not to show.

{ChildAdded:nil} & object

image
So, I designated the event as nil that I don’t want to see,
but it’s still automatically completed.

You can’t hide events or features of the original Instance. Only the Roblox API(Which you can’t modify to your liking) can do that. But you can replace it some how.

There’s an RFC for Shape Types which I believe is what you’re trying to achieve. Currently, the types for host-specified userdata are immutable so you can’t do this.

Nevertheless, what you’re trying to achieve isn’t going to scale well. You’d probably be better off just storing the object as a property of the class and then short-circuiting your properties/events through it.

self.Object = Object
self.ChildAdded = Object.ChildAdded

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