From 71f53e208dec262f3f7ecd88086845d1836d052f Mon Sep 17 00:00:00 2001 From: Alexander McCord <11488393+alexmccord@users.noreply.github.com> Date: Thu, 23 Sep 2021 12:09:43 -0700 Subject: [PATCH] Remove type refinements section We recently devoted significant effort to get this in a pretty good state where it works intuitively. As a result, this section is outdated. I'm deleting this because I think it's redundant to explain the same thing that intuition would also say. --- docs/_pages/typecheck.md | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/docs/_pages/typecheck.md b/docs/_pages/typecheck.md index 5f2aba6c..046aade9 100644 --- a/docs/_pages/typecheck.md +++ b/docs/_pages/typecheck.md @@ -317,42 +317,6 @@ local account: Account = Account.new("Alexander", 500) --^^^^^^^ not ok, 'Account' does not exist ``` -## Type refinements - -When we check the type of a value, what we're doing is we're refining the type, hence "type refinement." Currently, the support for this is somewhat basic. - -Using `type` comparison: -```lua -local stringOrNumber: string | number = "foo" - -if type(x) == "string" then - local onlyString: string = stringOrNumber -- ok - local onlyNumber: number = stringOrNumber -- not ok -end - -local onlyString: string = stringOrNumber -- not ok -local onlyNumber: number = stringOrNumber -- not ok -``` - -Using truthy test: -```lua -local maybeString: string? = nil - -if maybeString then - local onlyString: string = maybeString -- ok -end -``` - -And using `assert` will work with the above type guards: -```lua -local stringOrNumber: string | number = "foo" - -assert(type(stringOrNumber) == "string") - -local onlyString: string = stringOrNumber -- ok -local onlyNumber: number = stringOrNumber -- not ok -``` - ## Roblox types Roblox supports a rich set of classes and data types, [documented here](https://developer.roblox.com/en-us/api-reference). All of them are readily available for the type checker to use by their name (e.g. `Part` or `RaycastResult`).