-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_alias.lua
44 lines (34 loc) · 963 Bytes
/
generic_alias.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---@shape OurGenericShape<N>
---@field parameterOrNumber N | number
---@field aKnownStringLiteral 'a' | 'b' | 'c'
---@alias AliasAsParam 'one' | 'two' | 'three'
---@alias GenericAlias<N> string | OurGenericShape<N>
---@type GenericAlias<AliasAsParam>
local genericAlias = {
parameterOrNumber = 'one',
aKnownStringLiteral = 'a'
}
genericAlias = {
parameterOrNumber = 'two',
aKnownStringLiteral = 'b'
}
genericAlias = {
parameterOrNumber = 1,
aKnownStringLiteral = 'c'
}
genericAlias = {
parameterOrNumber = 'invalid', -- Expect error
aKnownStringLiteral = 'a'
}
genericAlias = {
parameterOrNumber = 'three',
aKnownStringLiteral = 'invalid', -- Expect error
}
genericAlias = { -- Expect error
parameterOrNumber = 'owner'
}
genericAlias = 'a string'
genericAlias = 1 -- Expect error
genericAlias = {} -- Expect error
---@type GenericAlias<"different">
local aDifferentGenericAlias = genericAlias -- Expect error