mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-19 11:13:49 +01:00
Write suggested details about typing
This commit is contained in:
parent
dff0c2a1d8
commit
455c93b6cf
1 changed files with 10 additions and 1 deletions
|
@ -92,7 +92,16 @@ local value = x?
|
||||||
|
|
||||||
This syntax would be based on expressions, and not identifiers, meaning that `(x or y)?.call()` would be valid syntax.
|
This syntax would be based on expressions, and not identifiers, meaning that `(x or y)?.call()` would be valid syntax.
|
||||||
|
|
||||||
The type of an expression using the nil-safety operator would simply resolve to the expression, nillable. Meaning if `dog.name` was a `string`, then `dog?.name` would be `string?`.
|
### Type
|
||||||
|
If the expression is typed as an optional, then the resulting type would be the final expression, also optional. Otherwise, it'll just be the resulting type if `?` wasn't used.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local optionalObject: { name: string }?
|
||||||
|
local optionalObjectName = optionalObject?.name -- resolves to `string?`
|
||||||
|
|
||||||
|
local nonOptionalObject: { name: string }
|
||||||
|
local nonOptionalObjectName = nonOptionalObject?.name -- resolves to `string`
|
||||||
|
```
|
||||||
|
|
||||||
## Drawbacks
|
## Drawbacks
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue