devexperts / devexperts/swagger-codegen-ts
prohibit extra fields in request payload
- Dominant language
- TypeScript
- Stars
- 80
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
problem: If I send the payload with extra fields, then I get an error in the rest. rest does not expect extra fields.
```typescript
interface ProductModify {
name: string;
}
interface Product extends ProductModify {
id: string;
foo: number;
}
const product: Product = { name: 'TEST', id: '1', foo: 1 };
const modifyProduct = (product: ProductModify) => {};
modifyProduct(product); // no type errors, because Product compatible with ProductModify
```
I propose to prohibit extra fields, i.e. disable polymorphism.
```typescript
type Impossible = {
[P in K]: never;
};
export type NoExtraProperties = U & Impossible>;
const modifyProduct = (product: NoExtraProperties) => {};
modifyProduct(product); // type error: Argument of type 'Product' is not assignable to parameter of type 'NoExtraProperties'
```
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue names no repository files or tests. Start by locating the TypeScript request-model generation entry point and any existing generated-type compatibility tests; completion means generated request types reject extra fields while accepting the declared fields in the ProductModify example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100