Skip to content

--module=ES2016 should re-write "index" imports #12597

Closed
@alexeagle

Description

@alexeagle

TypeScript allows shorthand for importing the index.ts file in a package. CommonJS does too.
However, this is not specified in ES2015 modules. Some loaders/bundlers support it (Rollup, Webpack) but some do not (Closure Compiler)

It would be more conservative to normalize these import locations to include the explicit /index suffix for better compatibility.
Repro:

$ ./node_modules/.bin/tsc -v
Version 2.0.10
$ cat import_index.ts
import {a} from './one';
console.log(a);
$ cat one/index.ts
export const a = 1;
$ cat tsconfig.json
{
    "compilerOptions": {
        "target": "es5",
        "experimentalDecorators": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "moduleResolution": "node",
        "module": "es6",
        "rootDir": "",
        "declaration": true,
        "lib": ["es6", "dom"],
        "baseUrl": ".",
        "types": []
    },
    "files": ["import_index.ts",
    "node_modules/@types/node/index.d.ts"]
}
$ ./node_modules/.bin/tsc
$ cat import_index.js
import { a } from './one';
console.log(a);

The proposal is this should have been written as import { a } from './one/index';

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn 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