jburzynski / TypeGen

Single-class-per-file C# to TypeScript generator
MIT License
197 stars 56 forks source link

Add 'type' in before import statements #161

Closed johan-timberit closed 1 year ago

johan-timberit commented 1 year ago

Hi! First of all, really go TS-generator!

I have a question though: Would it be possible to add 'type' to auto imported classes/interfaces genreted by typeGen?

Message in VS Code: "This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.ts(1371)"

Incorrect (generated by typeGen):

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

import { OrderNumber } from "./order-number";

export interface OrderNumberCreateCommand {
    orderNumberEntity: OrderNumber;
}

Correct (edited by myself)

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

import type { OrderNumber } from "./order-number";

export interface OrderNumberCreateCommand {
    orderNumberEntity: OrderNumber;
}
jburzynski commented 1 year ago

Hi, I'm glad it's useful! I added this functionality to version 4.4.0. It can be enabled with the useImportType option (or UseImportType in GeneratorOptions). It's disabled by default.

johan-timberit commented 1 year ago

Hi! Great! What would be the best way of using GeneratorOptions? I am simply generating on build (not programatically with API) and adding attributes on the classes I want generate.

Can GenerateOptions for example be added to a config file? For example "dotnet-typegen generate -c "path_to_config_file"?

image

Br Johan

jburzynski commented 1 year ago

Yes, you can add "useImportType": true in the config file. Most parameters which are in GeneratorOptions can be used in the config JSON and vice versa.

More details on using config files are here in the docs.

johan-timberit commented 1 year ago

Have I understodd i correctly that if I put a file in the root of the project, naming it "tgconfig.json", it will automatically used by typeGen?

I created such file and added

{ "useImportType": true }

Nothing happens when this is added.

Br Johan

jburzynski commented 1 year ago

There was a bug, it should be fixed in 4.4.1 and the config above should work.