Skip to content
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

is tsconfig's strictPropertyInitialization property safe to set false? #894

Closed
daimalou opened this issue May 3, 2024 · 3 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@daimalou
Copy link

daimalou commented May 3, 2024

Question

I am new to nestia, nestia is awesome.

I am using mongodb and using npx nestia setup --manager pnpm to setup nestia in my existing project.

But, I can't start dev server.

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';

@Schema()
export class Phone {
  @Prop({ default: false })
  isEnabled: boolean;

  @Prop({ unique: true })
  phone: string;

  @Prop()
  isReceiveAlert: boolean;
}

I see a lot of Typescript error in console. I need to change schame add ! to each class property like this.

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';

@Schema()
export class Phone {
  @Prop({ default: false })
  isEnabled!: boolean;

  @Prop({ unique: true })
  phone!: string;

  @Prop()
  isReceiveAlert!: boolean;
}

Meanwhile, I found that set strictPropertyInitialization to false in tsconfig.json can also solve this issue.

Is it safe to set this property to false and does it affect nestia?

@samchon samchon self-assigned this May 4, 2024
@samchon samchon added the question Further information is requested label May 4, 2024
@samchon
Copy link
Owner

samchon commented May 4, 2024

strictPropertyInitialization is recommended setting of tsconfig.json, due to ensure the class properties' types.

However, possible to configure it to be false, and no problem at the Nestia side.

@daimalou
Copy link
Author

daimalou commented May 4, 2024

@samchon thank you very much, can i just set "strict": false?

@samchon
Copy link
Owner

samchon commented May 4, 2024

Still possible, but never recommend.

If you configure the strict to be false, every types become T | null | undefined.

In my perspective view, strict: false means not to use TypeScript.

@samchon samchon closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants