Skip to content

Entry point of ts files at the package.json levelΒ #48084

Open
@StefanBrown

Description

@StefanBrown

Suggestion

πŸ” Search Terms

import ts without precompilation

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Support for importing ts files at the package level.

πŸ“ƒ Motivating Example

Adding typescript entry points ts-module and ts-import to package.json

{
  "version": "1.0.0",
  "name": "@scope/foo",
  "module": "dist/index.mjs",
  "main": "dist/index.js",
  "types": "types/index.d.ts",
  "ts-module": "src/index.ts",
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.js",
      "ts-import": "./src/index.ts"
    }
  }
}

πŸ’» Use Cases

This will improve the developer experience. No need to compile files, work directly from source codes. The types folder with d.ts files is no longer needed during custom code development.

When developing packages in the workspace, for example: @scope/foo, @scope/bar. (each package is compiled separately)
@scope/bar depends on @scope/foo.

index.ts in @scope/bar:

import { MyInterface } from '@scope/foo';  // !!!< scope/foo must be pre-compiled

Now, in order for this to work without compilation, and the import went straight from the source codes, you need to add the following construction to tsconfig.json:

"paths": {
  "@scope/foo": ["./foo/src/index"]
}

This approach has a problem after compiling @scope/bar with d.ts files.
d.ts files appear in DeclarationDir that are needed for another package (@scope/foo)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions