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
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
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};
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.
Most helpful comment
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:
This is the error I receive: