aral,
@aral@mastodon.ar.al avatar

If you use a parameter object in JavaScript, even if you specify its shape using JSDoc, you’ll only get errors if required properties are missing; not if there are extra properties provided.

e.g.,

class A {  
 /**  
 @param {{  
 id:string  
 }} params  
 */  
 constructor (params) {  
 Object.assign(this, params)  
 }  
}

// Error:  
new A({})

// No error:  
new A({id: 'x', foo:'bar'})  

According to this thread, it’s a fact-of-life:

https://stackoverflow.com/questions/49580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined

  • All
  • Subscribed
  • Moderated
  • Favorites
  • javascript
  • tacticalgear
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • khanakhh
  • Youngstown
  • ngwrru68w68
  • slotface
  • everett
  • rosin
  • thenastyranch
  • kavyap
  • GTA5RPClips
  • cisconetworking
  • JUstTest
  • normalnudes
  • osvaldo12
  • ethstaker
  • mdbf
  • modclub
  • Durango
  • tester
  • provamag3
  • cubers
  • Leos
  • anitta
  • megavids
  • lostlight
  • All magazines