simov / grant

OAuth Proxy
MIT License
4.08k stars 257 forks source link

use 'any' instead of 'object' on type definitions #236

Closed endel closed 3 years ago

endel commented 3 years ago

The reason for this change is because object is very restrictive, and you can't really access the contents of a GrantResponse freely, for example:

export interface GrantResponse {
  profile?: object
}

const grant: GrantResponse = {};
const id = grant.profile?.id; // Error: Property 'id' does not exist on type 'object'.(2339)

TypeScript playground URL: https://www.typescriptlang.org/play?#code/PQKhFgCgAIWhxATgQwHYBdqIKYGcAOA9qrtlLMFNgB5GKYCWG2iAZsgMbYIoYBKeIiW4BvclmQB3APwAuaIQBGAK2wd04-IkKsGAG2xyFKtRsgBfKFA7FcmAOa908pGnQCCt7gF5oI8wDcVpA2JIwAJtC+jm4AdFo6+oaxDOEBQA

simov commented 3 years ago

Thanks for the feedback @endel. I pushed a small change to use {[type: string]: any} instead of just any plus some other more specific definitions where possible.

The goal was to prevent assignments such as:

grant.profile = 0
grant.profile = ''

Let me know what you think.

simov commented 3 years ago

My proposal from above isn't going to work, so I reverted back most of the unknown object definitions to any. Probably a better approach could have been the use of unknown instead of any, but that would force everyone to define those objects, which can be seen as both good and bad depending on your point of view.

simov commented 3 years ago

Published in v5.4.13