Skip to content

Commit

Permalink
docs(result): add section about typechecking
Browse files Browse the repository at this point in the history
  • Loading branch information
lukadev-0 committed Feb 10, 2024
1 parent 6ef1f33 commit 255a4b0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/reference/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,42 @@ modified.
However, the value inside the `Result` may be mutable, so it is important to be aware
of this when working with `Result` values.

## Typechecking

The `Result` type aims to be as type-safe as possible, however due to Luau
limitations or bugs, some areas may not typecheck as expected.

### Callbacks

When calling a function through `:` syntax that takes a callback, the type of the
parameters aren't inferred.

```lua
local res = Result.Ok(5)
local mapped = res:map(function(value)
-- ┌────────────────────────── ^^^^^
-- └ this is typed as `a` instead of `number`
return value * 2
end)
```

This can be worked around by calling the function using `.` syntax:

```lua
local res = Result.Ok(5)

local mapped = Result.map(res, function(value)
-- ┌───────────────────────────────── ^^^^^
-- └ correctly typed as `number`
return value * 2
end)

-- the following is equivalent
local mapped = res.map(res, function(value)
return value * 2
end)
```

## Static Functions

### Result.Ok
Expand Down

0 comments on commit 255a4b0

Please sign in to comment.