Exclude other types from type in luau type check

I have written a custom instance module.

If I pass (workspace.aNpc) to the constructor function of this module,
it returns a custom instance.
This instance matches the type of workspace.aNpc , enhanced with 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 wish to exclude certain events or features from the original Instance.

{ChildAdded:nil} & object

image
Despite setting the undesired event to nil to exclude it, it still appears due to automatic completion.

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.