-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
I try to use absolute paths aliases for libraries. Output d.ts with aliased paths breaks type resolving, when package usesd as external package. Problem not resolved in typescript (see #18972).
Example:
my-lib/src/index.ts
export * from 'my-lib/some'
my-lib/dist/index.d.ts
export * from 'my-lib/some'
my-app.ts
import some from 'my-lib'
// ts does not check types here:
some.bla-bla
I wrote ts-transform-paths transfomer, which rewrites aliased import paths accordingly tsconfig baseUrl and paths.
With my trasformer my-lib/dist/index.d.ts
export * from './some'
It's works for npm packages and applications.
Problem:
Ts language service service.getEmitOutput(key, true)
ignores transformers in dts generation mode:
performance.mark("beforeEmit");
const transformers = emitOnlyDtsFiles ? [] : getTransformers(options, customTransformers);
In my transformer chain helper i use a emitFiles hack to keep some dts-related transformers. I use dts flag to indicate that plugin works for d.ts.
export interface CustomTransformer {
dts?: boolean
before?: ts.TransformerFactory<ts.SourceFile>
after?: ts.TransformerFactory<ts.SourceFile>
}
May be add posibility to filter dts related trasformers in typescript if emitOnlyDtsFiles given?
Something like this:
performance.mark("beforeEmit");
const transformers = getTransformers(options, customTransformers, emitOnlyDtsFiles);