Skip to content

Allow relative module IDs in ambient external module declarations? #1720

Closed
@csnover

Description

@csnover

Per direction from @mhegazy I’m opening this ticket as a discussion point for loosening the restriction forbidding relative module IDs in ImportDeclarations in AmbientModuleDeclaration. Loosening the restriction prevents the need to rewrite import declarations when combining multiple external declarations to a single file, and maybe simplifies some internals of the compiler (I haven’t checked, but it should eliminate some code branches).

Relative module IDs should be resolvable by the same way that the rest of the tsc machinery works, by resolving the reference according to the StringLiteral in a module’s own AmbientExternalModuleDeclaration. For example:

declare module 'foo/Foo' {
  import Bar = require('./Bar'); // resolve to `foo/Bar`
}

Right now you are not allowed to do this and need to write:

declare module 'foo/Foo' {
  import Bar = require('foo/Bar');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions