TurboScript icon indicating copy to clipboard operation
TurboScript copied to clipboard

Default arguments

Open MaxGraey opened this issue 7 years ago • 8 comments

class Vec4 {
     constructor(x: float32 = 0, y: float32 = 0, z: float32 = 0, w: float32 = 1) { 
           ... 
     }
}

~~and class Renderer { getContext(): RenderContext? { ... } }~~

MaxGraey avatar Mar 26 '17 21:03 MaxGraey

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

nidin avatar Mar 28 '17 05:03 nidin

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

MaxGraey avatar Mar 28 '17 07:03 MaxGraey

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

MaxGraey avatar Mar 28 '17 08:03 MaxGraey

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.

nidin avatar Mar 28 '17 11:03 nidin

We need to implement default arguments.

nidin avatar Mar 28 '17 11:03 nidin

Ok, I got it. So I rename topic just for default arguments

MaxGraey avatar Mar 28 '17 11:03 MaxGraey

Is this needed for v1, i'd vote for v2?

winksaville avatar Apr 12 '17 14:04 winksaville

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 .

nidin avatar Apr 12 '17 14:04 nidin