0.8.2 compiler issue?: getter with same name as type

Topics: General
Jan 22, 2013 at 3:31 PM

This code compiled fine in .8.1 but in .8.2 there seem to be a problem with getters with the same name as a type you are trying to use within the getter:

class TimeSpan
{
    _mMS = 0;

    constructor(x:number)
    {
        this._mMS = x;
    }
}


class Test
{
    public get TimeSpan() { return new TimeSpan(1000); }    // .8.2 compiler complains on "new TimeSpan(1000)" params do not match


    public get XTimeSpan() { return new TimeSpan(1000); }    // works in .8.2 compiler

    constructor()
    {
    }
}

 

 

Jan 22, 2013 at 3:35 PM

Just found out that it's somewhat even worse. The problem above I can get around by prefixing TimeSpan with the module but the same issue surfaces with system types like Date:

public get Date():Date
{
    return new Date(this._mInput.value);  // doesn't compile in .8.2
}

 

 

Jan 22, 2013 at 3:53 PM

The easy solution/workaround here is to use camelCase for your property names, which is the JavaScript way anyway.

On 22 Jan 2013 15:35, "BjornBacklund" <notifications@codeplex.com> wrote:

From: BjornBacklund

Just found out that it's somewhat even worse. The problem above I can get around by prefixing TimeSpan with the module but the same issue surfaces with system types like Date:

public get Date():Date
{
return new Date(this._mInput.value); // doesn't compile in .8.2
}

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jan 22, 2013 at 6:08 PM
Yes indeed but we have decided to stick with C# coding/naming style - half the project is done in C# and half in TS and switching between the environments seems to be easier if you keep the coding style. We also have lots of types that exist in both sides, so it makes sense naming them the same way.
This compiler issue also caused a nasty stack overflow bug: the code below is using a utility method GetEnum that takes the name of the Enum class as the first argument. Worked fine in 8.1 but will of course cause a stack overflow in 8.2 since Gender now refers to the getter function.
public get Gender() { return this.GetEnum( Gender, “Gender” ); }
---bjorn
From: markrendle
Sent: ‎January‎ ‎22‎, ‎2013 ‎7‎:‎53‎ ‎AM
To: bjorn@backlund.org
Subject: Re: 0.8.2 compiler issue?: getter with same name as type [typescript:430443]

From: markrendle

The easy solution/workaround here is to use camelCase for your property names, which is the JavaScript way anyway.

On 22 Jan 2013 15:35, "BjornBacklund" <notifications@codeplex.com> wrote:

From: BjornBacklund

Just found out that it's somewhat even worse. The problem above I can get around by prefixing TimeSpan with the module but the same issue surfaces with system types like Date:

public get Date():Date
{
return new Date(this._mInput.value); // doesn't compile in .8.2
}

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Jan 22, 2013 at 6:48 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jan 22, 2013 at 6:53 PM

Yep, this is a bug.

Jan 23, 2013 at 2:13 AM
BjornBacklund wrote:
Yes indeed but we have decided to stick with C# coding/naming style - half the project is done in C# and half in TS and switching between the environments seems to be easier if you keep the coding style. We also have lots of types that exist in both sides, so it makes sense naming them the same way...

Just remember not to use K&R indent style like the C# industry standard. There is a good reason why Allman is the industry standard for JavaScript - ASI. That's one element of JavaScript code style that isn't as subjective as casing.

Jan 24, 2013 at 10:11 PM
Qube wrote:
BjornBacklund wrote:
Yes indeed but we have decided to stick with C# coding/naming style - half the project is done in C# and half in TS and switching between the environments seems to be easier if you keep the coding style. We also have lots of types that exist in both sides, so it makes sense naming them the same way...

Just remember not to use K&R indent style like the C# industry standard. There is a good reason why Allman is the industry standard for JavaScript - ASI. That's one element of JavaScript code style that isn't as subjective as casing.

Correction. It actually looks like the compiler converts brace placement to Allman style for blocks. But literals (arrays, objects etc.) are compiled as provided, so:

function doSomething
{
    return
    {
        intoThe: 'void'
    };
}

Is compiled to:

function doSomething() {
    return;
 {
        intoThe:
'void'
    }
    ;
}