luau
luau copied to clipboard
Any sort of union type alias fails to preserve the (aliased/synthetic) name
For example:
type A = {
b: (self: A, a: number) -> A,
} | {
c: number
}
function foo(a: A) end
foo(1234)
The error here does not preserve the type alias A leading to: TypeError: Type 'number' could not be converted into 't1 where t1 = { b: (t1, number) -> t1 } | { c: number }'Luau1000
This does not just apply to cyclic type definitions either, for example, the below union also fails to preserve name:
type A = {
b: (a: number) -> number,
} | {
c: number
}
function foo(a: A) end
foo(1234)
Errors with:
TypeError: Type 'number' could not be converted into '{ b: (number) -> number } | { c: number }'Luau[1000](https://luau-lang.org/typecheck)
Expected result: all of the above cases should error with TypeError: Type 'number' could not be converted into A instead of losing the type aliased name and making debugging 500 times more difficult and painful.