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

names of types and variables do not allow a reserved word to be used. #26995

Closed
puppy0cam opened this issue Sep 10, 2018 · 3 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@puppy0cam
Copy link

TypeScript Version: 3.1.0-dev.20180907

Search Terms:
names of types still parse keywords
type name interprets reserved words
declaring names cannot use keywords
reserved words cannot be used

Code

export namespace Problematic {
    export type 'class' = string | null;
    export var 'class': string | null = "";
    export const 'class': string | null = "";
    export ['class']: string | null = "";
    type 'class' = string;
    export type class = string | null;
    export var class: string | null = "";
    export var class = "";
}
export interface StrangelyOk {
    class: Problematic.class;
}

Expected behavior:
a member would be declared with the name of 'class', and I could access that member from other objects
Actual behavior:
errors occur that prohibit the name being declared, however objects that attempt to access the member simply claim that it does not have a member of that name exported.
Playground Link:
Playground
Related Issues:
None found

@DanielRosenwasser
Copy link
Member

You can use an export declaration with a local name that's not reserved, and any identifier for an exported name.

declare namespace Foo {
    var _class;
    export { _class as class };
}

Foo.class

@DanielRosenwasser DanielRosenwasser added the Question An issue which isn't directly actionable in code label Sep 11, 2018
@pineapplemachine
Copy link

I'm converting some JS code to TS. The JS module I'm working on exports a function with a "null" attribute added. The obvious export const null = ... produces a syntax error, and I've ended up here trying to find a workaround.

The solution @DanielRosenwasser gave may have worked in an earlier version of TypeScript, but in latest (3.2.4) I get a syntax error with this example code:

export namespace MyNamespace {
    const _null = "My Constant";
    export {_null as null};
}

This is the error I receive:

error TS1194: Export declarations are not permitted in a namespace.
3     export {_null as null};

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants