Skip to content

module name mismatch in declaration #34624

@andyfleming

Description

@andyfleming

TypeScript Version: 3.7.0-dev.20191021

Search Terms:

  • declaration
  • modules

Code

https://github.com/andyfleming/typescript-module-declaration-mismatch-repro

Expected behavior:

A valid index.d.ts file should be emitted.

Actual behavior:

The module is declared as "versions.static" on line 1, but is imported below as "versions.static.js" on line 10 (and not found).

https://github.com/andyfleming/typescript-module-declaration-mismatch-repro/blob/master/js/index.d.ts#L1

https://github.com/andyfleming/typescript-module-declaration-mismatch-repro/blob/master/js/index.d.ts#L10

Steps to reproduce

  1. Clone https://github.com/andyfleming/typescript-module-declaration-mismatch-repro
  2. Run npm install
  3. Run npm run generate-types
  4. Observe declared "versions.static" module and import attempt as "versions.static.js".

Code from Repo

package.json

{
  "name": "@example-org/example-package",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "generate-types": "rm js/index.d.ts && tsc",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/andyfleming/typescript-module-declaration-mismatch-repro.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/andyfleming/typescript-module-declaration-mismatch-repro/issues"
  },
  "homepage": "https://github.com/andyfleming/typescript-module-declaration-mismatch-repro#readme",
  "devDependencies": {
    "typescript": "3.7.0-dev.20191021"
  }
}

tsconfig.json

/* Generated with tsc --init via TypeScript 3.7.0-beta */
{
  "compilerOptions": {
    "module": "commonjs",
    "allowJs": true,
    "declaration": true,
    "outFile": "./js/index.js",
    "emitDeclarationOnly": true,
    "strict": true,
    "esModuleInterop": true
  },
  "include": [
    "js/**/*"
  ]
}

js/index.js

import versions from './versions.static.js';

export {
    versions
};

js/versions.static.js

export default {
    "@a/b": "1.0.0",
    "@a/c": "1.2.3"
};

js/index.d.ts (sample output)

declare module "versions.static" {    // <-- declared one way here
    var _default: {
        "@a/b": string;
        "@a/c": string;
    };
    export default _default;
}
declare module "index" {
    export { versions };
    import versions from "versions.static.js";   // <-- and different way here
}

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions