Description
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)