-
-
Notifications
You must be signed in to change notification settings - Fork 124
fix(core): defensive symbol/type handling in MethodTransformer (#1382) #1448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/test-sdk/features/method-transformer-defensive/nestia.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { INestiaConfig } from "@nestia/sdk"; | ||
|
|
||
| export const NESTIA_CONFIG: INestiaConfig = { | ||
| input: ["src/controllers"], | ||
| output: "src/api", | ||
| clone: true, | ||
| swagger: { | ||
| output: "swagger.json", | ||
| }, | ||
| }; | ||
| export default NESTIA_CONFIG; |
35 changes: 35 additions & 0 deletions
35
tests/test-sdk/features/method-transformer-defensive/src/controllers/ImportTypeController.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { TypedRoute } from "@nestia/core"; | ||
| import { Controller } from "@nestjs/common"; | ||
|
|
||
| @Controller("import-type") | ||
| export class ImportTypeController { | ||
| @TypedRoute.Get("envelope") | ||
| public envelope(): IEnvelope<IGreeting> { | ||
| return { message: "ok", data: { greeting: "hello" } }; | ||
| } | ||
|
|
||
| @TypedRoute.Get("alias") | ||
| public alias(): AliasEnvelope<IGreeting> { | ||
| return { message: "ok", data: { greeting: "hello" } }; | ||
| } | ||
|
|
||
| @TypedRoute.Get< | ||
| import("./ImportTypeController").IEnvelope< | ||
| import("./ImportTypeController").IGreeting | ||
| > | ||
| >("decorator-generic") | ||
| public decoratorGeneric(): AliasEnvelope<IGreeting> { | ||
| return { message: "ok", data: { greeting: "hello" } }; | ||
| } | ||
| } | ||
|
|
||
| export interface IEnvelope<T> { | ||
| message: string; | ||
| data: T | null; | ||
| } | ||
|
|
||
| export interface IGreeting { | ||
| greeting: string; | ||
| } | ||
|
|
||
| type AliasEnvelope<T> = IEnvelope<T>; |
42 changes: 42 additions & 0 deletions
42
.../test-sdk/features/method-transformer-defensive/src/controllers/InlineReturnController.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { TypedRoute } from "@nestia/core"; | ||
| import { Controller } from "@nestjs/common"; | ||
|
|
||
| @Controller("inline-return") | ||
| export class InlineReturnController { | ||
| @TypedRoute.Get("anonymous") | ||
| public anonymous(): Promise<{ foo: string; bar?: number }> { | ||
| return Promise.resolve({ foo: "ok" }); | ||
| } | ||
|
|
||
| @TypedRoute.Get("intersection") | ||
| public intersection(): Promise<IX & IY> { | ||
| return Promise.resolve({ x: 1, y: "hi" }); | ||
| } | ||
|
|
||
| @TypedRoute.Get("return-type") | ||
| public returnType(): Promise<ReturnType<typeof getItem>> { | ||
| return Promise.resolve(getItem()); | ||
| } | ||
|
|
||
| @TypedRoute.Get("inferred") | ||
| public inferred(): Promise<InferReturn<() => IItem>> { | ||
| return Promise.resolve({ id: 1, label: "item" }); | ||
| } | ||
| } | ||
|
|
||
| interface IX { | ||
| x: number; | ||
| } | ||
| interface IY { | ||
| y: string; | ||
| } | ||
| interface IItem { | ||
| id: number; | ||
| label: string; | ||
| } | ||
|
|
||
| type InferReturn<T> = T extends (...args: any[]) => infer R ? R : never; | ||
|
|
||
| function getItem(): IItem { | ||
| return { id: 1, label: "item" }; | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
tests/test-sdk/features/method-transformer-defensive/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "../../config/tsconfig.json", | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "@api": ["./src/api"], | ||
| "@api/lib/*": ["./src/api/*"], | ||
| }, | ||
| }, | ||
| "include": ["src"], | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.