Handle Undefined Attributes with TypeScript #446
-
|
Hi, I've got a method in a class like so: interface CreateUserDto {
email: string;
firstName: string;
lastName: string;
middleInitial?: string;
organization: string;
department: string;
phone: string;
altEmail?: string;
jobTitle: string;
designation: Designation;
accessExpirationDate: string;
}
createUser = (user: CreateUserDto) => {
this.#logger.debug("Inserting into cosmos_user", JSON.stringify(user));
return this.#sql`
insert into cosmos_user ${this.#sql(user as Required<CreateUserDto>)}
`;
};Unless I cast createUser = (user: CreateUserDto) => {
this.#logger.debug("Inserting into cosmos_user", JSON.stringify(user));
const newUser = {altEmail: null, middleInitial: null, ...user };
return this.#sql`
insert into cosmos_user ${this.#sql(newUser)}
`;
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I thought #447 should fix that 👍 |
Beta Was this translation helpful? Give feedback.
I thought
sqlinsert helpers calls where already acceptingundefined... It seams I was wrong 😕 Actually, it's not an issue with theundefinedtransform, but with the insert helper on objects that has someundefinedproperties (it does matter whether or notundefinedcalls are transformed to somethinhg else in this case, asundefinedproperties could just be ignored when encoded anyway).#447 should fix that 👍