You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
generator can't bundle generic types correctly when I not import generic type before.
path alias replace not working in import(...).
I don't know how to describe him, please see the following code.
Input code
The following examples are composed of three files, I will comment the file names. And I used path alias in tsconfig.json. e.g. ~/ redirect to src/
// interface/request.ts// this file is shared for all caseexporttypeRequestProxyResult<T,R={data: T;[key: string]: any},>=Promise<ResponseProxyExtraRaw<T,R>>exporttypeResponseProxyExtraRaw<T,R=any>=T&{$raw: R}
// utils/index.ts// this file is shared for all caseimport{RequestProxyResult}from'~/interfaces/request'exportconstfoo=(): RequestProxyResult<{}>=>{// not care this, just force asserting a typereturn{}asany}
case 1:
If the implicit type definition is not imported manually.
// index.case1.tsimport{foo}from'~/utils'exportconstcase1=foo()// case1 type is RequestProxyResult<{}, { [key: string]: any; data: {};}>, this type automatically inferred from ts
And run generator. It say build/index.d.ts(10,25): error TS2707: Generic type 'RequestProxyResult' requires between 1 and 2 type arguments. Lost generic type. The generated files are as follows
// index.case2.tsimport{foo}from'~/utils'import{ResponseProxyExtraRaw}from'~/interfaces/request'// <-------- Just import the type file, but not import required implicit typeexportconstcase2=foo()
dts Output:
// Generated by dts-bundle-generator v6.1.0exportdeclaretypeRequestProxyResult<T,R={data: T;[key: string]: any;}>=Promise<ResponseProxyExtraRaw<T,R>>;exportdeclaretypeResponseProxyExtraRaw<T,R=any>=T&{$raw: R;};exportdeclareconstcase2: import("~/interfaces/request").RequestProxyResult<{},{// <--------- import("~/") path alias not replace.[key: string]: any;data: {};}>;export{};
case 3:
This case is worked. Also the expected output.
// index.case3.tsimport{foo}from'~/utils'import{RequestProxyResult}from'~/interfaces/request'// <-------- import the type file, and import required implicit type, aka`RequestProxyResult`exportconstcase3=foo()// aka: RequestProxyResult<...>
I'm afraid this is a bug of typescript compiler since it generates incorrect d.ts output. This statement import("~/interfaces/request") cannot work without your tsconfig so most likely this shouldn't be like that (it should be resolved to ./interfaces/request for example like in the case 1). Thus please create an issue in https://github.com/microsoft/TypeScript for this case.
timocov
changed the title
incorrect path alias replace in import(...) and lost gerenic types
Lost gerenic type argument from import() statements
Dec 5, 2021
Bug report
Hi, guys, I ran into two problems.
import(...)
.I don't know how to describe him, please see the following code.
Input code
The following examples are composed of three files, I will comment the file names. And I used path alias in tsconfig.json. e.g.
~/
redirect tosrc/
case 1:
If the implicit type definition is not imported manually.
And run generator. It say
build/index.d.ts(10,25): error TS2707: Generic type 'RequestProxyResult' requires between 1 and 2 type arguments.
Lost generic type. The generated files are as followscase 2:
dts Output:
case 3:
This case is worked. Also the expected output.
Output:
Expected output
See above
Actual output
See above
Reproduce Repository
https://github.com/Innei/dts-reproduction
Additional context
Thanks.
The text was updated successfully, but these errors were encountered: