Visitar URL original
[misc] Specify length of toArray return type by mongoose700 · Pull Request #5766 · moment/moment · GitHub
Skip to content

[misc] Specify length of toArray return type - #5766

Merged
marwahaha merged 3 commits into
moment:developfrom
mongoose700:patch-1
Oct 29, 2020
Merged

marwahaha merged 3 commits into
moment:developfrom
mongoose700:patch-1

Conversation

@mongoose700

Copy link
Copy Markdown
Contributor

toArray will always return an array with seven numbers. This change is necessary to be able to do new Date(...m.toArray()). As just number[], it complains with Expected 0-7 arguments, but got 0 or more..

toArray will always return an array with seven numbers. This change is necessary to be able to do `new Date(...m.toArray())`. As just `number[]`, it complains with `Expected 0-7 arguments, but got 0 or more.`.
@mongoose700 mongoose700 changed the title Specify length of toArray return value [misc] Specify length of toArray return value Oct 28, 2020
@coveralls

coveralls commented Oct 28, 2020 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.03%) to 88.525% when pulling 31bee3f on mongoose700:patch-1 into 0dcaaa6 on moment:develop.

@marwahaha

Copy link
Copy Markdown
Member

Interesting.

Is this TS 1.x compatible?

Otherwise, you can update the ts3.1 typings.

@mongoose700

Copy link
Copy Markdown
Contributor Author

Tuples were added in 1.3, so not quite.

@marwahaha

Copy link
Copy Markdown
Member

@mongoose700 Thanks for the update. Could you also add a test https://github.com/moment/moment/blob/develop/ts3.1-typing-tests/moment-tests.ts and I'll merge it

@mongoose700

Copy link
Copy Markdown
Contributor Author

I wanted to add a test that invoked new Date(...moment().toArray()), but the spread syntax wasn't available, and apply isn't type-safe.

@marwahaha

Copy link
Copy Markdown
Member

Thanks!

@Dustin4444

Copy link
Copy Markdown

toArray will always return an array with seven numbers. This change is necessary to be able to do new Date(...m.toArray()). As just number[], it complains with Expected 0-7 arguments, but got 0 or more..

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.

5 participants