acacode / acacode/swagger-typescript-api
Missing 'type' keyword in generated files when importing from data-contracts
- Ngôn ngữ chính
- TypeScript
- Star
- 4.1k
- Fork
- 436
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Hi there,
With the following command: `npx swagger-typescript-api -p --responses --modular --axios --unwrap-response-data --route-types --output ./src/api/types/ --name api-types.ts`
The following correct files are generated:

However, inside `ConsultRequests.ts` the types from `data-contracts.ts` are imported but should be prefixed with `type`
```typescript
// ConsultRequests.ts
import {
CommunicationMessage,
CommunicationMessageOptional,
ConsultRequest,
ConsultRequestListCollection,
InvalidContentTypeProblemDetails,
InvalidRequestBodyProblemDetails,
Item,
ItemHistory,
ProblemDetails,
} from "./data-contracts";
```
When running `vue-tsc`, which Typescript checks the project for type errors:
```bash
vue-tsc --noEmit
src/api/types/ConsultRequests.ts:12:1 - error TS1371: This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.
12 import {
~~~~~~~~
13 CommunicationMessage,
~~~~~~~~~~~~~~~~~~~~~~~
...
21 ProblemDetails,
~~~~~~~~~~~~~~~~~
22 } from "./data-contracts";
~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:13:3 - error TS1444: 'CommunicationMessage' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
13 CommunicationMessage,
~~~~~~~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:14:3 - error TS1444: 'CommunicationMessageOptional' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
14 CommunicationMessageOptional,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:15:3 - error TS1444: 'ConsultRequest' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
15 ConsultRequest,
~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:16:3 - error TS1444: 'ConsultRequestListCollection' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
16 ConsultRequestListCollection,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:17:3 - error TS1444: 'InvalidContentTypeProblemDetails' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
17 InvalidContentTypeProblemDetails,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:18:3 - error TS1444: 'InvalidRequestBodyProblemDetails' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
18 InvalidRequestBodyProblemDetails,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:19:3 - error TS1444: 'Item' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
19 Item,
~~~~
src/api/types/ConsultRequests.ts:20:3 - error TS1444: 'ItemHistory' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
20 ItemHistory,
~~~~~~~~~~~
src/api/types/ConsultRequests.ts:21:3 - error TS1444: 'ProblemDetails' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
21 ProblemDetails,
~~~~~~~~~~~~~~
src/api/types/ConsultRequests.ts:23:35 - error TS1444: 'RequestParams' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
23 import { ContentType, HttpClient, RequestParams } from "./http-client";
~~~~~~~~~~~~~
src/api/types/Statistics.ts:12:1 - error TS1371: This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.
12 import { ConsultRequestStatistics, ProblemDetails } from "./data-contracts";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/types/Statistics.ts:12:10 - error TS1444: 'ConsultRequestStatistics' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
12 import { ConsultRequestStatistics, ProblemDetails } from "./data-contracts";
~~~~~~~~~~~~~~~~~~~~~~~~
src/api/types/Statistics.ts:12:36 - error TS1444: 'ProblemDetails' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
12 import { ConsultRequestStatistics, ProblemDetails } from "./data-contracts";
~~~~~~~~~~~~~~
src/api/types/Statistics.ts:13:22 - error TS1444: 'RequestParams' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
13 import { HttpClient, RequestParams } from "./http-client";
~~~~~~~~~~~~~
```
## Workaround
I can disable/remove `--modular` from the command, and then all the Typescript errors are resolved.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.