5 ms·
> For example, the data might contain additional fields or even incorrect values for declared types. I understand 'incorrect values' (this is true, see https:/
by nailer 6y ago
> For example, the data might contain additional fields or even incorrect values for declared types.
I understand 'incorrect values' (this is true, see https://github.com/Microsoft/TypeScript/issues/15480 https://github.com/Microsoft/TypeScript/issues/15480) .
But TypeScript definitely doesn't like adding additional fields. Right now I'm working on TypeScript, added the new Fastify raw body plugin, and forgot to extend our custom Request type. The error is:
Property 'rawBody' does not exist on type 'CustomRequest<DefaultQuery, DefaultParams, DefaultHeaders, any>'.ts(2339)
Ie, we can't just add a field.
Appreciate I may be wrong, or we have different definitions here, but I'd like to discuss.
- nicolodavis 6y agoSomething like this is valid TypeScript I think? interface MyType { a: number; } function process(value: MyType) { console.log(value); } const value = { a: 1, b: 2 }; process(value);