--!strict
type Object<T> = {
type: T
}
type Thing = {
[string | Object<any>]: any
}
function ret<T>(t: T)
return t
end
local _: Thing = ret {
[{ type = "hello" } :: Object<"hello">] = 2,
[{ type = "foo" } :: Object<"foo">] = "hello!", -- type error, but there shouldn't be
hello = workspace
}
There are two TypeErrors here:
TypeError: Type
'Object<"foo">'
could not be converted into
'Object<"hello">'
caused by:
Property 'type' is not compatible.
Type '"foo"' could not be converted into '"hello"' in an invariant context
TypeError: Type 'string' could not be converted into 'number'
It appears so. I keep running into many related type checker errors because Luau infers the strictest type based on the first item in the table, so I have to add a load of ugly type casts everywhere