Odd Union table behaviour #3299
johannesrld
started this conversation in
General
Replies: 1 comment
-
|
Note that I don't actually think this is a bug, but it would be nice to get the former behaviour instead of the latter somehow. The majority of the time the actual behaviour I want out of a union would be the discrete behaviour instead of the current behaviour where unions produce one congealed "super" table of all tables in the union. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Union types in LuaLS seem to work fine with primitive types, typing something like
---@alias numberOrString number | stringcorrectly denotes that the type of a value can either be a number or a string.Where union types get a bit strange is when you use them with tables, e.g. take a union like this one:
Other type checkers usually type check this in the obvious way: you can either pass a table with a "value1" prop1 and a number in prop2, or a "value2" prop1 with a string in prop2.
What this union type is actually type checked as is:
This feels really odd to me, because this would also accept a table such as
{prop1: "value1", prop2: "teststring"}despite never actually explicitly allowing a type such as{prop1: "value1", prop2: string}in the unionBeta Was this translation helpful? Give feedback.
All reactions