You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ A superset of Roku's BrightScript language. Compiles to standard BrightScript.
11
11
12
12
## Overview
13
13
14
-
**WARNING: this is the v0.66.0 branch with experimental features**
14
+
**WARNING: this is the `v1` branch with experimental features**
15
15
16
16
The BrighterScript language provides new features and syntax enhancements to Roku's BrightScript language. Because the language is a superset of BrightScript, the parser and associated tools (VSCode integration, cli, etc...) work with standard BrightScript (.brs) files. This means you will get benefits (as described in the following section) from using the BrighterScript compiler, whether your project contains BrighterScript (.bs) files or not. The BrighterScript language transpiles to standard BrightScript, so your code is fully compatible with all roku devices.
BrighterScript supports declaring custom named types using the `type` keyword. In this way, new types can be created as wrappers, or aliases for other types. This is useful to create custom names for advanced types like unions, so they can be more easily used throughout the code.
4
+
5
+
## Syntax
6
+
7
+
To create a new custom named types, use the syntax `type <customName> = <existingType>` at either the top level of a file, or within a namespace.
8
+
9
+
For example, if you wanted to create a shorthand for the union type `integer or float or double`, you could do the following:
10
+
11
+
```BrighterScript
12
+
type number = integer or float or double
13
+
14
+
function sum(x as number, y as number) as number
15
+
return x + y
16
+
end function
17
+
18
+
function product(x as number, y as number) as number
19
+
return x * y
20
+
end function
21
+
```
22
+
23
+
<details>
24
+
<summary>View the transpiled BrightScript code</summary>
25
+
26
+
```BrightScript
27
+
function sum(x as dynamic, y as dynamic) as dynamic
28
+
return x + y
29
+
end function
30
+
31
+
function product(x as dynamic, y as dynamic) as dynamic
32
+
return x * y
33
+
end function
34
+
```
35
+
36
+
</details>
37
+
38
+
## Importing
39
+
40
+
Types created with the `type` keyword are available through importing the file they are declared in.
41
+
42
+
For example:
43
+
44
+
**src/components/Widget.bs**
45
+
46
+
```BrighterScript
47
+
namespace Widgets
48
+
49
+
type widget = Button or Checkbox
50
+
51
+
interface Button
52
+
text as string
53
+
action as function
54
+
end interface
55
+
56
+
interface Checkbox
57
+
text as string
58
+
checked as boolean
59
+
end interface
60
+
end namespace
61
+
```
62
+
63
+
**src/components/UI.bs**
64
+
65
+
```BrighterScript
66
+
import "pkg:/components/Widget.bs" ' provides the "Widgets.widget" type
0 commit comments