TurboScript
TurboScript copied to clipboard
Default arguments
class Vec4 {
constructor(x: float32 = 0, y: float32 = 0, z: float32 = 0, w: float32 = 1) {
...
}
}
~~and class Renderer { getContext(): RenderContext? { ... } }~~
In second example did you mean optional return. In that case following is more declarative since we need either void or a type.
getContext():void|type
Sure, in Typescript uses type|void or type|null but since TurboScript is a superset of TypeScript we can have a convenient alternative. I think declaration of optional returning type better in Swift-like manner: this representation is more compact.
Another variant:
getContext()?: RenderContext
Which more compatible form with argument optionals
However according to this: https://github.com/Microsoft/TypeScript/issues/7426
That proposal decline in TypeScript. The main problem is to determine what is type?
, it is a type | null | undefined
or type | undefined
which very sensitive to strict equality
getContext()?: RenderContext
If above signature means getContext
return RenderContext
or null
we dont need ?
operator since all types are nullable.
getContext(): RenderContext {
return null;
}
above code is valid. Also optional return is not possible since at compile time there must be only one type. Multiple return types must be handled with interfaces
.
We need to implement default arguments.
Ok, I got it. So I rename topic just for default arguments
Is this needed for v1, i'd vote for v2?
Let's move it to V2 since it's not blocking basic functionality
On Wed 12. Apr 2017 at 4:21 PM, Wink Saville [email protected] wrote:
Is this needed for v1, i'd vote for v2?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/01alchemist/TurboScript/issues/21#issuecomment-293592735, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMGZuRTFsWCh0VBw46teltZH9A_a4N-ks5rvN3ggaJpZM4Mpmhx .