Skip to content

Add TypeScript definition#11

Merged
sindresorhus merged 1 commit intosindresorhus:masterfrom
BendingBender:typescript-defs
Apr 22, 2019
Merged

Add TypeScript definition#11
sindresorhus merged 1 commit intosindresorhus:masterfrom
BendingBender:typescript-defs

Conversation

@BendingBender
Copy link
Contributor

No description provided.

// OMG, YES!
```
*/
declare function negativeArray<T extends readonly unknown[]>(array: T): T;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause the returned array to be readonly too? If yes, I'm not sure it's worth it, as we decided it's not worth returning readonly array as it's inconvenient for the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is not what's happening here. This is just a base type, this means that if the incoming type is an ReadonlyArray then the result will also be one, if the incoming type is a plain Array then the resulting type will be an Array.

This is even covered by the tests.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I should have looked at the tests... But thanks for the explanation. I was not sure how the readonly keyword worked with the base type.

@sindresorhus sindresorhus merged commit 9077d13 into sindresorhus:master Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments