Skip to content

Add undefined to return type of array-last#447

Open
sunnyzanchi wants to merge 1 commit into
angus-c:masterfrom
sunnyzanchi:master
Open

Add undefined to return type of array-last#447
sunnyzanchi wants to merge 1 commit into
angus-c:masterfrom
sunnyzanchi:master

Conversation

@sunnyzanchi
Copy link
Copy Markdown

It's possible for array-last to return undefined, so it should be included in the return type. If there's a more sophisticated typing that makes sense here i'm happy to change it

✔️ Updated tests and yarn test-types passes

It's possible for array-last to return `undefined`,
so it should be included in the return type
@angus-c
Copy link
Copy Markdown
Owner

angus-c commented Apr 30, 2022

Not a TS expert so I may be wrong, but I don't this change is necessary.
See https://tinyurl.com/2p9fjbct. (this is with StrictNullChecks on)

Also in index.tests.ts probably just needs
const test8: undefined = last([undefined]);

@sunnyzanchi
Copy link
Copy Markdown
Author

in this example, the definition of last errors with dynamic arrays — i think this is maybe from a newer version of TS, i don't remember this happening before. last2 doesn't let TS catch that d might be undefined. i think the type definition of last3 is the only one that covers all cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants