Yarn.social Online Meetup 25th May (See: #fcghsma for details)

Yarn

Recent twts in reply to #rggw75q

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

```js

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-typesc … ⌘ Read more

⤋ Read More

Participate

Login to join in on this yarn.