Language reference · section 20
20. Types
Feature: Types
Scenario: Annotations use a colon
Given a parameter, a return type, or a binding with a type
Then the annotation uses name: type, "): type:", or name: type = expr
Scenario: Annotations pass to TypeScript in regular code
Given a regular function with annotations
When the file is built
Then TypeScript checks the annotations
Scenario: A type can be a union
Given the annotation "number | string"
Then the value can be either a number or a string
Scenario: A type can be an array
Given the annotation "number[]"
Then the value is an array of numbers
Scenario: A type can be grouped
Given the annotation "(number | string)[]"
Then the value is an array of numbers or strings
Scenario: A type alias is not part of the language
Given the code "type P = number"
Then the compiler reports an error
Scenario: An untyped parameter is any
Given a parameter without an annotation
Then its type is any in the .d.ts file
Scenario: wasm parameters and results use only int, float, and boolean
Given a @wasm function with a parameter typed number
Then the compiler reports an error "type `number` is not allowed in @wasm functions; use int, float, or boolean"
Scenario: Every wasm parameter needs an int, float, or boolean annotation
Given a @wasm function with an unannotated parameter n
Then the compiler reports an error "parameter n needs an int, float, or boolean annotation"
Scenario: A wasm function needs a return type
Given a @wasm function without a return type
Then the compiler reports an error "@wasm f needs a return type annotation"