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

Allow quoted names in ambient contexts #9846

Closed
RyanCavanaugh opened this issue Jul 20, 2016 · 5 comments
Closed

Allow quoted names in ambient contexts #9846

RyanCavanaugh opened this issue Jul 20, 2016 · 5 comments
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Jul 20, 2016

The node module yargs is callable (typeof require('yargs') === 'function'). It also has a property named default that is a function.

This makes writing a definition file very difficult. You'd be inclined to write

declare function yargs(): void;
declare namespace yargs {
  /* dozens of other things */
  function default(): void; // syntax error
}
export = yargs;

There's not an obvious workaround that doesn't have bad side effects (e.g. rewriting the whole mess as a var doesn't really work in the case where there's a nested class), possibly requiring a massive restructuring of the entire file.

Wherever an identifier appears in an ambient context where it could have been initialized as a property, it should be allowed to be quoted. For example

export const "default": string;
declare namespace foo {
  function "with"(): string;
}
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jul 20, 2016
@RyanCavanaugh
Copy link
Member Author

This actually prevents some objects from being correctly represented. Consider if you had some object foo that was legal to use as

class d extends foo.var { }
let d = new foo.var();
let e = foo.default;

@RyanCavanaugh
Copy link
Member Author

@mhegazy
Copy link
Contributor

mhegazy commented Nov 29, 2017

Note that export { x as y} is legal in a namespace in an ambient context. so the issue in the OP can be written as:

declare function yargs(): void;
declare namespace yargs {
    function _default(): void; 
    export { _default as _default };
}
export = yargs;

@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
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

3 participants