typescript-rest-swagger icon indicating copy to clipboard operation
typescript-rest-swagger copied to clipboard

Unknown Type: IntersectionType

Open FrikkieSnyman opened this issue 7 years ago • 4 comments

Hello, I've come across a very strange bug.

I have a class named Application located in ./entities/Application.ts, with the following definition

export class Application {
    test: string;
}

I also have an application-controller located in ./controllers/application-controller.ts with the following contents:

import { POST, Path } from 'typescript-rest';
import { Application } from '../entities/Application';
/**
 * This is a demo operation to show how to use typescript-rest library.
 */
@Path('/application')
export class ApplicationController {
    /**
     * Create an application
     * @param application The Application entity that is to be created
     * @return Promise<Application> The Application that has just been created
     */
    @POST
    async createApplication(application: Application): Promise<Application> {
        // some async stuff
        return application;
    }
}

When I run npm run swagger

I get the following output:

There was a problem resolving type of 'Application'.
~/.../node_modules/typescript-rest-swagger/dist/metadata/methodGenerator.js:57
                throw new Error("Error generate parameter method: '" + controllerId.text + "." + methodId.text + "' argument: " + parameterId.text + " " + e);
                ^

Error: Error generate parameter method: 'ApplicationController.createApplication' argument: application Error: Unknown type: IntersectionType
    at ~/.../node_modules/typescript-rest-swagger/dist/metadata/methodGenerator.js:57:23

So the strange thing is, that if I change the name of the class Application to something else (like Test or Application1) swagger runs fine.

This is very strange behaviour. Am I missing something?

FrikkieSnyman avatar Nov 27 '17 14:11 FrikkieSnyman

Did you ever resolve this issue? I have the same issue.

mnishizawa avatar Jan 21 '18 04:01 mnishizawa

Same problem

plopezm avatar Mar 14 '18 17:03 plopezm

@mnishizawa Sorry for only replying now.

I had to workaround it by just renaming the class to a different, more specifice name...

FrikkieSnyman avatar Apr 03 '18 14:04 FrikkieSnyman

I too faced this issue and fixed it with the solution suggested by @FrikkieSnyman The reason I think, it worked, is because of the conflict with some existing class name. In my case, I was exporting type User and a class at another place with name User

dpkshrma avatar Aug 10 '18 19:08 dpkshrma