mirror of
https://github.com/luau-lang/rfcs.git
synced 2025-05-04 10:43:48 +01:00
removed typelib.is*() and added typelib.type() instead
This commit is contained in:
parent
86223cfb38
commit
5722f85152
1 changed files with 9 additions and 24 deletions
|
@ -25,7 +25,7 @@ end
|
||||||
For instance, the `rawget` type function can be written as:
|
For instance, the `rawget` type function can be written as:
|
||||||
```luau
|
```luau
|
||||||
type function rawget(tbl, prop)
|
type function rawget(tbl, prop)
|
||||||
if not typelib.istable(tbl) then
|
if not typelib.type(tbl) == "table" then
|
||||||
error("First argument is not a table!") -- fails to reduce
|
error("First argument is not a table!") -- fails to reduce
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,9 +82,9 @@ All attributes of newly created typelib are initialized with empty tables / arra
|
||||||
| `unknown` | `typelib` | an immutable runtime representation of the built-in type `unknown` |
|
| `unknown` | `typelib` | an immutable runtime representation of the built-in type `unknown` |
|
||||||
| `never` | `typelib` | an immutable runtime representation of the built-in type `never` |
|
| `never` | `typelib` | an immutable runtime representation of the built-in type `never` |
|
||||||
| `any` | `typelib` | an immutable runtime representation of the built-in type `any` |
|
| `any` | `typelib` | an immutable runtime representation of the built-in type `any` |
|
||||||
| `boolean()` | `typelib` | returns an immutable runtime representation of the built-in type `boolean` |
|
| `boolean` | `typelib` | returns an immutable runtime representation of the built-in type `boolean` |
|
||||||
| `number()` | `typelib` | returns an immutable runtime representation of the built-in type `number` |
|
| `number` | `typelib` | returns an immutable runtime representation of the built-in type `number` |
|
||||||
| `string()` | `typelib` | returns an immutable runtime representation of the built-in type `string` |
|
| `string` | `typelib` | returns an immutable runtime representation of the built-in type `string` |
|
||||||
|
|
||||||
| Instance Methods | Return Type | Description |
|
| Instance Methods | Return Type | Description |
|
||||||
| ------------- | ------------- | ------------- |
|
| ------------- | ------------- | ------------- |
|
||||||
|
@ -101,22 +101,7 @@ All attributes of newly created typelib are initialized with empty tables / arra
|
||||||
| `newtable(props: {[typelib]: typelib}?, indexer: {key: typelib, value: typelib}?)` | `typelib` | returns a mutable runtime representation of a `table` type |
|
| `newtable(props: {[typelib]: typelib}?, indexer: {key: typelib, value: typelib}?)` | `typelib` | returns a mutable runtime representation of a `table` type |
|
||||||
| `newmetatable(props: {[typelib]: typelib}?, indexer: {key: typelib, value: typelib}?, metatable: typelib?)` | `typelib` | returns a mutable runtime representation of a metatable. `metatable` argument needs to be the same type as `typelib.newtable()` |
|
| `newmetatable(props: {[typelib]: typelib}?, indexer: {key: typelib, value: typelib}?, metatable: typelib?)` | `typelib` | returns a mutable runtime representation of a metatable. `metatable` argument needs to be the same type as `typelib.newtable()` |
|
||||||
| `newfunction(parameters: {typelib} \| typelib?, returns: {typelib} \| typelib?)` | `typelib` | returns a mutable runtime representation of a `function` type. Calling `newfunction(X)` will by default set `parameters` to `X` |
|
| `newfunction(parameters: {typelib} \| typelib?, returns: {typelib} \| typelib?)` | `typelib` | returns a mutable runtime representation of a `function` type. Calling `newfunction(X)` will by default set `parameters` to `X` |
|
||||||
| `isnil(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the built-in type `nil` |
|
| `type(arg: typelib)` | `string` | returns the tag of the argument ("nil", "unknown", "never", "any", "boolean", "number", "string", "boolean singleton", "string singleton", "negation", "union", "intersection", "table", "metatable", "function", "class") |
|
||||||
| `isunknown(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the built-in type `unknown` |
|
|
||||||
| `isnever(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the built-in type `never` |
|
|
||||||
| `isany(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the built-in type `any` |
|
|
||||||
| `isnegation(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of a `Negation` |
|
|
||||||
| `isboolean(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the built-in type`boolean` |
|
|
||||||
| `isnumber(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the built-in type `number` |
|
|
||||||
| `isstring(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the built-in type `string` |
|
|
||||||
| `isstringsingleton(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of a string singleton |
|
|
||||||
| `isbooleansingleton(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of a boolean singleton |
|
|
||||||
| `isunion(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the union type |
|
|
||||||
| `isintersection(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of the intersection type |
|
|
||||||
| `istable(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of a `table` type |
|
|
||||||
| `ismetatable(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of a metatable represented as a special property of the `table` type |
|
|
||||||
| `isfunction(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of a `function` type |
|
|
||||||
| `isclass(arg: typelib)` | `boolean` | returns true if the argument is syntactically a runtime representation of a `class` type |
|
|
||||||
| `copy(arg: typelib)` | `typelib` | returns a deep copy of the argument |
|
| `copy(arg: typelib)` | `typelib` | returns a deep copy of the argument |
|
||||||
|
|
||||||
#### Negation
|
#### Negation
|
||||||
|
@ -199,16 +184,16 @@ The build / analysis times will also be negatively impacted as reducing type fun
|
||||||
|
|
||||||
Currently, the runtime representation of types is a userdata called `typelib`. Another representation is to use the already-existing type in Luau `table`; instead of serializing types into `typelib`, we can serialize them into tables with predefined properties. For instance, the representation for a string singleton `"abc"` could be `{type = "stringSingleton", value = "abc"}`. So instead of writing:
|
Currently, the runtime representation of types is a userdata called `typelib`. Another representation is to use the already-existing type in Luau `table`; instead of serializing types into `typelib`, we can serialize them into tables with predefined properties. For instance, the representation for a string singleton `"abc"` could be `{type = "stringSingleton", value = "abc"}`. So instead of writing:
|
||||||
```luau
|
```luau
|
||||||
type function isSingleton(t)
|
type function issingleton(t)
|
||||||
if typelib.isstringsingleton(t) then
|
if typelib.type(t) == "string singleton" then
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
developers could write:
|
developers could write:
|
||||||
```luau
|
```luau
|
||||||
type function isSingleton(t)
|
type function issingleton(t)
|
||||||
if t.type == "stringSingleton" then
|
if t.type == "string singleton" then
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue