Back to questions
JuniorTheoryCommon
What does tsc report for this file?
interface User {
id: number;
name: string;
email: string;
}
type Preview = Omit<User, "email">;
const p: Preview = { id: 1, name: "Ann", email: "ann@mail.com" };An error: Preview has no property email
- Expecting
Omitto makeemailoptional, likePartial: it removes the property, so a literal that still sets it fails the extra-property check. - Confusing
OmitwithPick:Omit<User, "email">keepsidandnameand drops onlyemail.
- How would you write the same
PreviewwithPick? - Why does the same object with
emailpass when it is stored in a variable first?