I'm facing a problem. I need to expose a 'type' in an @ApiProperty of swagger on my API. But swagger don't accept it. I looked in many website to find solution but I did not find any.
Here is the error I get:
TS2693: 'testTest' only refers to a type, but is being used as a value here.
type testTest = 'A' | 'B';
@ApiProperty({
type: testTest,
example: 'fr',
})
test: testTest;
I can't use something else since the type I need to use is from an external library.
You cannot use a TypeScript
type
as a value fortype
in Swagger becausetype
you are importing from the said library is not available at runtime, or once its transpiled to javascript. its only used for type checking. Thats how typescript works. This is same for any type, interfaces, return types etc...What I suggest you do is to have a variable hold the values in
type testTest = 'A' | 'B';