acacode / acacode/swagger-typescript-api

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

Aberta
#580 6 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
4.1k
Forks
436
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.