What I want to achieve is to reference the original interface, and remove some attributes. This is my original interface:
export interface IInvitations {
parent: Parse.User;
visitor: Visitors;
dates: IInvitationDateAndPin[];
}
When a user initiates the invitation, he should not give parent
as a parameter. which will be auto-assigned before saving into the database. So I made a new interface to omit it:
export interface ICInvitations extends IInvitations {
parent: never;
}
But then I cannot successfully assign value to this interface.
let data: ICInvitations = {
visitor: Visitors,
datas: [...]
}
It shows Property 'parent' is missing in type
. But the type is never, which I failed to assign anything into it.
The React. js error "Property is missing in type but required in type" occurs when we don't pass all of the required props to a component. To solve the error, make sure to pass all of the props the component requires, e.g. <MyComponent name="Tom" age={30} /> or mark its props as optional.
The error "Type is missing the following properties from type" occurs when the type we assign to a variable is missing some of the properties the actual type of the variable expects. To solve the error, make sure to specify all of the required properties on the object.
The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names. Copied!
TypeScript introduced a new type never , which indicates the values that will never occur. The never type is used when you are sure that something is never going to occur. For example, you write a function which will not return to its end point or always throws an exception.
As Jeff mentioned, while you can't remove the property from the interface, you can reuse most of it by doing something like this (Omit
is shipped with TypeScript 3.5):
export interface ICInvitations extends Omit<IInvitations, 'parent'> {
parent?: never;
}
The parent?: never
part is optional, but will let you get an error if anyone tries to construct something implementing this interface with a value set for parent
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With