Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Default arguments #21

Open
MaxGraey opened this issue Mar 26, 2017 · 8 comments
Open

Default arguments #21

MaxGraey opened this issue Mar 26, 2017 · 8 comments

Comments

@MaxGraey
Copy link
Contributor

MaxGraey commented Mar 26, 2017

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

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

@nidin
Copy link
Contributor

nidin commented Mar 28, 2017

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

@MaxGraey
Copy link
Contributor Author

MaxGraey commented Mar 28, 2017

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
Copy link
Contributor Author

MaxGraey commented Mar 28, 2017

However according to this: microsoft/TypeScript#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

@nidin
Copy link
Contributor

nidin commented Mar 28, 2017

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
Copy link
Contributor

nidin commented Mar 28, 2017

We need to implement default arguments.

@MaxGraey
Copy link
Contributor Author

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

@MaxGraey MaxGraey changed the title Optinal and default arguments Default arguments Mar 28, 2017
@nidin nidin added the v1.0.0 label Mar 28, 2017
@nidin nidin added this to the v1.0.0 milestone Mar 28, 2017
@nidin nidin added the ready label Apr 7, 2017
@winksaville
Copy link
Contributor

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

@nidin
Copy link
Contributor

nidin commented Apr 12, 2017 via email

@winksaville winksaville added v2.0.0 and removed v1.0.0 labels Apr 12, 2017
@nidin nidin removed this from the v1.0.0 milestone May 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants