You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
problem: If I send the payload with extra fields, then I get an error in the rest. rest does not expect extra fields.
interfaceProductModify{name: string;}interfaceProductextendsProductModify{id: string;foo: number;}constproduct: Product={name: 'TEST',id: '1',foo: 1};constmodifyProduct=(product: ProductModify)=>{};modifyProduct(product);// no type errors, because Product compatible with ProductModify
I propose to prohibit extra fields, i.e. disable polymorphism.
typeImpossible<Kextendskeyofany>={[PinK]: never;};exporttypeNoExtraProperties<T,UextendsT=T>=U&Impossible<Exclude<keyofU,keyofT>>;constmodifyProduct=<TextendsProductModify>(product: NoExtraProperties<ProductModify,T>)=>{};modifyProduct(product);// type error: Argument of type 'Product' is not assignable to parameter of type 'NoExtraProperties<ProductModify, Product>'
The text was updated successfully, but these errors were encountered:
Geksanit
changed the title
prohibit extra field in request payload
prohibit extra fields in request payload
Feb 4, 2024
This can be easily done by wrapping each generated type into io-ts' exact.
On the other hand, it is desirable sometimes to pass extra fields to the server, for example for features like "custom data" where the system objects can be extended with customer-specific fields.
problem: If I send the payload with extra fields, then I get an error in the rest. rest does not expect extra fields.
I propose to prohibit extra fields, i.e. disable polymorphism.
The text was updated successfully, but these errors were encountered: