Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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) .

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.



Something 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);




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: