Skip to content

Sibling namespace missing name from import in allowJs declaration #38834

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

TypeScript Version: 4.0.0-dev.20200528

Search Terms: javascript declaration js dot array notation namespace

Code

index.js:

export const colors = {
  royalBlue: "#6400e4",
};

export const brandColors = {
  purple: colors.royalBlue,
};

Expected behavior:

When compiled with tsc --allowJs --declaration --emitDeclarationOnly index.js, it should export:

export namespace colors {
    export const royalBlue: string;
}
export namespace brandColors {
    import purple = colors.royalBlue;
    export { purple };
}

Actual behavior:

Instead, we get:

export namespace colors {
    export const royalBlue: string;
}
export namespace brandColors {
    import purple = royalBlue;
    export { purple };
}

Note the import purple = royalBlue;. It's missing colors..

Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "checkJs": true,
    "allowJs": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

Related Issues: The closest issues I could find were #36270 and #33626...

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions