nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.27k stars 7.58k forks source link

`nest build` throws compilation errors about typescript `Omit` type util #3630

Closed thatkookooguy closed 4 years ago

thatkookooguy commented 4 years ago

Bug Report

Current behavior

When I run nest build, I get Errors for either incorrect things or things in node_modules

But when I run npm run start:dev, everything works and the application runs

Input Code

Repo: https://github.com/Kibibit/achievibit/tree/next

Notice that the code in question is in the next branch

Reproduce steps:

  1. Clone the repo and install dependencies
  2. Try to run the application with npm run start:dev
  3. Try to build the application with nest build

Some suspects:

Here's the output when running nest build:

node_modules/@nestjs/swagger/dist/decorators/api-body.decorator.d.ts:4:35 - error TS2304: Cannot find name 'Omit'.

4 declare type RequestBodyOptions = Omit<RequestBodyObject, 'content'>;
                                    ~~~~
node_modules/@nestjs/swagger/dist/decorators/api-header.decorator.d.ts:3:43 - error TS2304: Cannot find name 'Omit'.

3 export interface ApiHeaderOptions extends Omit<ParameterObject, 'in'> {
                                            ~~~~
node_modules/@nestjs/swagger/dist/decorators/api-param.decorator.d.ts:4:33 - error TS2304: Cannot find name 'Omit'.

4 declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
                                  ~~~~
node_modules/@nestjs/swagger/dist/decorators/api-property.decorator.d.ts:2:45 - error TS2304: Cannot find name 'Omit'.

2 export interface ApiPropertyOptions extends Omit<SchemaObjectMetadata, 'name' | 'enum'> {
                                              ~~~~
node_modules/@nestjs/swagger/dist/decorators/api-property.decorator.d.ts:8:80 - error TS2344: Type '"type" | "enum" | "example" | "format" | "deprecated"' does not satisfy the constraint '"name" | "enum"'.
  Type '"type"' is not assignable to type '"name" | "enum"'.

8 export declare function ApiResponseProperty(options?: Pick<ApiPropertyOptions, 'type' | 'example' | 'format' | 'enum' | 'deprecated'>): PropertyDecorator;
                                                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@nestjs/swagger/dist/decorators/api-query.decorator.d.ts:4:33 - error TS2304: Cannot find name 'Omit'.

4 declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
                                  ~~~~
node_modules/@nestjs/swagger/dist/decorators/api-response.decorator.d.ts:3:46 - error TS2304: Cannot find name 'Omit'.

3 export interface ApiResponseMetadata extends Omit<ResponseObject, 'description'> {
                                               ~~~~
node_modules/@nestjs/swagger/dist/decorators/api-response.decorator.d.ts:9:48 - error TS2304: Cannot find name 'Omit'.

9 export interface ApiResponseSchemaHost extends Omit<ResponseObject, 'description'> {
                                                 ~~~~
node_modules/@nestjs/swagger/dist/document-builder.d.ts:20:14 - error TS2304: Cannot find name 'Omit'.

20     build(): Omit<OpenAPIObject, 'components' | 'paths'>;
                ~~~~
node_modules/@nestjs/swagger/dist/interfaces/schema-object-metadata.interface.d.ts:3:47 - error TS2304: Cannot find name 'Omit'.

3 export interface SchemaObjectMetadata extends Omit<SchemaObject, 'type' | 'required'> {
                                                ~~~~
node_modules/@nestjs/swagger/dist/swagger-module.d.ts:4:58 - error TS2304: Cannot find name 'Omit'.

4     static createDocument(app: INestApplication, config: Omit<OpenAPIObject, 'paths'>, options?: SwaggerDocumentOptions): OpenAPIObject;
                                                           ~~~~
src/models/user.model.ts:31:18 - error TS2345: Argument of type '{ required: boolean; }' is not assignable to parameter of type 'ApiPropertyOptions'.
  Object literal may only specify known properties, and 'required' does not exist in type 'ApiPropertyOptions'.

31   @ApiProperty({ required: false })
                    ~~~~~~~~~~~~~~~

Found 12 error(s).

All of them excepts the last one are from node_modules. The last one says that required does not exist in type ApiPropertyOptions, even though it clearly does exist there :-)

When looking at the decorator's declaration files, you can see that ApiPropertyOptions also uses the Omit utility type, so it might be related? Screen Shot 2019-12-12 at 6 18 37 PM

Expected behavior

nest build should build with no false errors

Possible Solution

Possibly a version I need to update or some configuration param that I need to set :-)

Pretty sure it's related to the Omit type which makes me think it's related to the typescript version, but looks like the version is pretty up-to-date (latest = 3.7.3, installed = 3.6.3)

Environment


Nest version:
```
"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",
"@nestjs/mongoose": "^6.1.2",
"@nestjs/platform-express": "^6.7.2",
"@nestjs/swagger": "^4.0.9",
```

Nest CLI version: `6.12.7`

For Tooling issues:
- Node version: `v10.15.0`  
- Platform: `MacOS Mojave 10.14.6` 

Others:

thatkookooguy commented 4 years ago

don't know what happened, but it looks fine now

evrend commented 4 years ago

I have same problem when I deploy my app with dokku. These versions are same with my local.

Typescript v3.7.3 Npm v6.12.1 Node v12.13.1

I found a solution but I think it is'nt a good solution. I need a real fix. Open file tsconfig.json and add this line:

{
    compilerOptions: {
        "skipLibCheck": true
    }
}
kamilmysliwiec commented 4 years ago

Updating TypeScript fixes this issue. skipLibCheck: true is fine as well