Closed DimitarBogdanov closed 4 months ago
There is a draft RFC for negation types: https://github.com/luau-lang/rfcs/pull/29. Typically, this would mean you could write your example as Holder & ~Part
, but it places restrictions on structural types, which is your primary concern.
So the operator you're proposing here would cover a different use case, I just wanted to point out that if the negation type RFC was able to test negated structural types, it would cover your use case as well.
Also, it doesn't look like there are any type operations that could be mistaken for value operations, and I think that's because of casting; it happens inside expressions that execute at runtime.
-- what could this mean?
local a = b :: T / U
-- it could be one of:
local a = (b :: T) / U
local a = b :: (T / U)
Perhaps you could use the symbol set theory/Wikipedia uses, the backslash \
character.
This design looks a lot like omit<T, keyof<U>>
so this is really asking for an omit
type family.
And yeah, the design conflicts with local a = b :: T / U
as above.
Also, it doesn't look like there are any type operations that could be mistaken for value operations, and I think that's because of casting; it happens inside expressions that execute at runtime.
I did not consider the fact that types appear in expressions, you're correct. I agree with the backslash idea, actually like it a bit more.
This design looks a lot like omit<T, keyof> so this is really asking for an omit type family.
100% plausible, I'm not very well vested in TS.
Going to close this. https://github.com/luau-lang/rfcs will be the right place to submit such a feature request.
Problem
Consider this:
It's possible to create a type like
M
without writing the property names individually.But it's not possible to create a type like
M
which excludes properties from another type.Use case
You have an Instance which has many objects in it. You want to use the Instance as a dictionary, where you can use e.g.
part.Decal
and use the child decal. This is certainly doable!Now you want to make a function which returns the
Holder
type.But you don't want your function's consumer to have access to irrelevant methods such as
GetChildren
andName
on theHolder
type. This is where a difference of sets comes in place (coloured area):So we want to get everything from
Holder
and remove everything fromPart
on it. This could look something like thisAnd boom! Now we can return
Holder
and we won't see anything fromPart
. P.S. I use/
instead of-
as the suggested syntax, because a minus looks awkward to me, but it's definitely not the only possible way!