acacode / acacode/swagger-typescript-api

Missing 'type' keyword in generated files when importing from data-contracts

Open
#580 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.1k
Forks
436
PR merge metrics
No merged PRs in 30d

Description

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:
![image](https://github.com/acacode/swagger-typescript-api/assets/15127381/4d415a6a-9a3c-462d-8191-5e16acc87805)

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.