rbxts-flamework / core

Flamework is an extensible game framework. It requires typescript and offers many useful features.
MIT License
101 stars 8 forks source link

Modding.Generic<T, "guard"> fails to pass nominal types due to intersection with primitives #104

Closed DaDerpDuck closed 6 months ago

DaDerpDuck commented 6 months ago

I use nominal types to help differentiate between regular strings and strings that come from a serialized object. For example, this is what I use to create nominal types:

export type SerializedObject = string & { readonly __nominal: "SerializedObject" };

The issue with this is that the guard builds to be:

t.intersection(t.string, t.interface({
    __nominal = t.literal("SerializedObject"),
}))

This type guard will always fail due to requiring an intersection between a primitive and a table. Therefore, I cannot usefully guard against any nominal types.