You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typefoo<T> = { bar:T? }
localfoo:foo<any> = { bar="foobar" }
-- TypeError: Type '{ bar: string }' could not be converted into 'foo<any>'; type { bar: string }[read "bar"] (string) is not exactly foo<any>[read "bar"][0] (any)-- type { bar: string }[read "bar"] (string) is not exactly foo<any>[read "bar"][1] (nil)localfoo:foo<any> = { } -- TypeError: Type '{ }' could not be converted into 'foo<any>localfoo:foo<nil> = { } -- TypeError: Type '{ }' could not be converted into 'foo<nil>
Thanks for the report! This is for the new solver correct? I agree that the last two examples seem like bugs: we should be able to infer that {} is a { bar: T? }.
local foo: foo<any> = { bar = "foobar" }
I'm not actually sure that should be legal though. The rules for typing any / error can be tricky.
I'm not actually sure that should be legal though. The rules for typing any / error can be tricky.
My intuition is that any should allow any type to be used for that field-- and that generics shouldn't change this behavior. This is the behavior in the old solver. If the example in question was illegal, I would have a hard time understanding why these would be legal:
My intuition is that any should allow any type to be used for that field ...
Yes, that's the right intuition, I wasn't sure if that fully applied in a generic position.
There's some logic in the new solver that ensures when you write table literals we infer the correct type. For example, if I write {}, that's an empty table and gets the type {}. It could be a { foo: number? }, but those are different types (only one allows you to assign a number to foo). I'm guessing that logic is not working here. It seems like any works as you'd expect in other scenarios, e.g.:
type Foo<T> = { bar: T? }
local function castFoo(f: Foo<string>): Foo<any>
return f
end
These return type errors:
The following will not error:
The text was updated successfully, but these errors were encountered: