peerigon / clockodo

Unofficial JavaScript/TypeScript SDK for Clockodo
MIT License
20 stars 10 forks source link

Improve parameter strictness #130

Open jhnns opened 1 year ago

jhnns commented 1 year ago

The Clockodo SDK has been previously designed in a way to allow additional parameters that haven't been typed yet. E.g. imagine there is a new parameter we haven't added to the function type yet:

clockodo.getUser({
  newParam: true
});

In TypeScript, this would show an error because of the "excess property check". We extend all params with Record<string, unknown> to allow new, untyped params.

As a downside, this also makes it possible to missspell properties and TypeScript will allow it:

clockodo.getUser({
  // TS allows this because it thinks it's a new param
  oldButMisspelledParam: true
});

I think, we should remove & Record<string, unknown> thus making the type check more strict. As a downside, the SDK will now show an error if a new, untyped param is used. However, I think this can be easily fixed:

clockodo.getUser({
  // New, untyped param. Remove this once it got added to the SDK
  // @ts-expect-error
  newParam: true
});

This way, it will show a TypeScript error as soon as the type is added and the ts-expect-error is not necessary anymore. With us working more actively on the SDK, I think we should try to get the complete API typed and up-to-date.

What do you think @mrclickbits @anki247 @dsumer ?