luaut-parser 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/index.cjs +360 -33
- package/dist/index.d.cts +37 -4
- package/dist/index.d.ts +37 -4
- package/dist/index.js +359 -33
- package/package.json +1 -3
package/README.md
CHANGED
|
@@ -117,6 +117,39 @@ name: T | nil -- must be written, but may be nil
|
|
|
117
117
|
Omitting an argument requires `?` (or a default), as in TypeScript — a
|
|
118
118
|
parameter typed `T | nil` still has to be passed something.
|
|
119
119
|
|
|
120
|
+
**Classes** — types are structural, except for classes. A definitions file
|
|
121
|
+
declares one with `declare class`, and it is nominal, as Roblox's classes are:
|
|
122
|
+
|
|
123
|
+
```luau
|
|
124
|
+
declare class BasePart extends PVInstance { Size: Vector3 }
|
|
125
|
+
declare class Part extends BasePart { Shape: EnumItem }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
A `Part` is a `BasePart` and an `Instance` because it extends them. A
|
|
129
|
+
`ReplicatedStorage` is not a `Part`, and no table literal is an `Instance`,
|
|
130
|
+
however alike their members. A class still fits a shape that names members it
|
|
131
|
+
has (`{ Name: string }`). It is not a table, though, so `typeof(part)` picks
|
|
132
|
+
the `"Instance"` overload, not `"table"`. Members are inherited, and a subclass
|
|
133
|
+
may narrow one (`Parent: SomeFolder`).
|
|
134
|
+
|
|
135
|
+
**Callbacks** — a function written where a function type is expected takes
|
|
136
|
+
its parameter types from it: in `signal:Connect(function(player) ... end)`,
|
|
137
|
+
`player` is typed from `Connect`. The same applies to an annotated `const`
|
|
138
|
+
and to an assignment such as `remote.OnServerInvoke = function(player) ...`.
|
|
139
|
+
|
|
140
|
+
**Type packs** — `type Signal<T... = ...any> = { Connect: (self, cb: (T...) -> ()) -> () }`.
|
|
141
|
+
A pack parameter takes every type argument from its position on:
|
|
142
|
+
`Signal<Player, string>`, `Signal<()>` for none.
|
|
143
|
+
|
|
144
|
+
**Operators** — on a type that declares metamethods (`__add`, `__mul`,
|
|
145
|
+
`__unm`, ...), an operator has the metamethod's result, tried on the left
|
|
146
|
+
operand and then the right one, as Luau does. So `Vector3 + Vector3` and
|
|
147
|
+
`2 * vector` are both `Vector3`.
|
|
148
|
+
|
|
149
|
+
**Qualified type names** — a definitions file may declare `Enum.Material`
|
|
150
|
+
(`declare class Enum.Material extends EnumItem {}`), and code writes it the
|
|
151
|
+
same way.
|
|
152
|
+
|
|
120
153
|
**Calls** — every argument is checked against its parameter, and a generic
|
|
121
154
|
parameter against its constraint (`GetService<K extends keyof Services>`
|
|
122
155
|
rejects `""`).
|