Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show warning if use "name" as static class property #7932

Closed
terbooter opened this issue Apr 7, 2016 · 2 comments
Closed

Show warning if use "name" as static class property #7932

terbooter opened this issue Apr 7, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@terbooter
Copy link

Actual behavior:

class WSPacketEvent {
    public static name = "WSPacketEvent";

    constructor(public target:WS, public packet:InPacket) {

    }
}

function addListeners(ws:WS) {
        ws.on(WSPacketEvent.name, this.onPacket); 
       //Runtime error. 
       //TypeError: Cannot assign to read only property 'name' 
       //of function WSPacketEvent(target, packet) 
}

This is because of function's property "name" is read only in ES6
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name

If remove assignment

class WSPacketEvent {
    //public static name = "WSPacketEvent";

    constructor(public target:WS, public packet:InPacket) {

    }
}

function addListeners(ws:WS) {
        ws.on(WSPacketEvent.name, this.onPacket); 
       //Compile error. 
       //Error:(18, 29) TS2339: Property 'name' does not exist on type 'typeof WSPacketEvent'.
}

Expected behavior:

  1. Show warning when try to write to class static property named "name"
  2. Do not show error if try to read from class static property named "name", which was not explicitly declared in TS code

TypeScript Version:
1.8.9 --target ES7

@terbooter terbooter changed the title Should show warning if use "name" as static class property Show warning if use "name" as static class property Apr 7, 2016
@TheMohanraj
Copy link

Same here..

ClassHere['name'] is an ugly workaround

@mhegazy
Copy link
Contributor

mhegazy commented Apr 7, 2016

same issue in #442

@mhegazy mhegazy closed this as completed Apr 7, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 7, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants