I want something like this:
type Thing = ...
local _: Thing = {
-- ok:
[5] = 2,
hello = workspace,
-- not ok:
[2] = "hello",
foo = 5,
}
Number keys can only be numbers, and string keys can only be Instances.
I tried this:
--!strict
type Thing = {
[number]: number,
} & {
[string]: Instance
}
local _: Thing = {
[5] = 2,
hello = workspace
}
Unfortunately, this does not work:
TypeError: Type '_' could not be converted into '{number} & {| [string]: Instance |}'
caused by:
Not all intersection parts are compatible.
Type '_' could not be converted into '{| [string]: Instance |}'
caused by:
Property '[indexer key]' is not compatible.
Type 'number' could not be converted into 'string' in an invariant context
How do I do this? Is it possible?