8000 Allow quoted names in ambient contexts · Issue #9846 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Allow quoted names in ambient contexts #9846
Closed
@RyanCavanaugh

Description

@RyanCavanaugh

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0