When running with typescript >= 2.7 and strictPropertyInitialization or strict compiler options enabled, the schema types like:
import { Field, ObjectType } from "type-graphql";
@ObjectType({ description: "User profile" })
export class Profile {
@Field()
firstname: string;
@Field()
lastname: string;
@Field()
bio: string;
}
will cause compiler errors like:
Error:(6, 3) TS2564: Property 'firstname' has no initializer and is not definitely assigned in the constructor.
Is there a good workaround for this that doesn't involve writing an unnecessary constructor or disabling this check for the entire project?
The root cause of this is my biggest gripe with the typescript decorators in that they cannot be read at run-time when applied to interfaces.
export class Profile {
@Field()
firstname!: string;
@Field()
lastname!: string;
@Field()
bio!: string;
}
Most helpful comment