nestia icon indicating copy to clipboard operation
nestia copied to clipboard

Support: Type export by implicit inference

Open ltnscp9028 opened this issue 4 months ago • 1 comments

The feature proposal you're describing suggests supporting to export implicit types inferred.

for Example,

@Controller('foo')
export class FooController {
    @Post()
    foo(@Body() body: {fooRequest: string}) {
        return {foo: 'bar'}
    }
}

In the code below, I expect the type inference to be as follows:

interface FooControllerFooRequest {
  fooRequest: string
}

interface FooControllerFooResponse {
  foo: string
}

The interface content doesn't necessarily need to this pattern (Controller class name + Controller class method + Request/Response).

Only, It can be any value that is easy for users to distinguish.

This enables Nestia users to convert implicit type inference into explicit type inference through Nestia.

Also support migration through nestia.

e.g. npx nestia migrate implict command,

AS-IS

@Controller('foo')
export class FooController {
    @Post()
    foo(@Body() body: {fooRequest: string}) {
        return {foo: 'bar'}
    }
}

TO-BE

@Controller('foo')
export class FooController {
    @Post()
    foo(@Body() body: FooRequest): FooResponse {
        return {foo: 'bar'}
    }
}

To achieve this, export type support is necessary. Alternatively, users can create a type in a path specified by them.

If Support this feature, Nestia-driven development becomes feasible.

ltnscp9028 avatar Feb 20 '24 18:02 ltnscp9028

The new cli command would be npx nestia explicit

samchon avatar Feb 24 '24 10:02 samchon