Comments (1)
@sindresorhus asked me to cross post a reply I made to a comment by @ootidea on #647 here.
Looking at this issue, I'm not sure that they're directly applicable (I agree that this issue is probably a bug), but since it might lead to other issues being created, I'll go ahead and put them here.
Please don't forget to tag me if you'd like me to discuss further, otherwise I'll probably miss it in my inbox!
@ootidea's comment:
#647 (comment)
LastArrayElement<[]> should be undefined, but it is never.
LastArrayElement<T[]> should be T | undefined, but it is T.
LastArrayElement<[...1[], 2]> should be 2, but it is 1 | 2.
LastArrayElement<[1, 2?]> should be 1 | 2, but it is never.
LastArrayElement<[1?, 2?]> should be 1 | 2 | undefined, but it is never.
LastArrayElement<[0, 1, 2?, ...3[]]> should be 1 | 2 | 3, but it is 0 | 1 | 2 | 3 | undefined.
LastArrayElement should be any, but it is unknown.
@ahrjarrett's response:
#647 (comment)
For instance, the expectation that LastArrayElement<[]> return undefined is useful only as the return type of a term-level JavaScript function that gets the last element of an array, or returns undefined if the array is empty.
My 2 issues with this:
Array.prototype.last does not exist (AFAIK). You could write a function called last that behaves the way you describe -- but you could also write a function that returns an error message if the array is empty, is throws, or does any number of things instead. Choosing undefined out of any other option feels somewhat arbitrary.
This doesn't seem to be in alignment with the design goals of type-fest, since it doesn't export (AFAIK) any term-level API. If someone tried to compose LastArrayElement with another type-level function, getting undefined would be very surprising behavior, because the only way that would happen would be if the value undefined was in the array.
from type-fest.
Related Issues (20)
- Is it possible to Omit native type like booleans or numbers? HOT 3
- `MergeDeep` doesn't preserve `readonly` modifier HOT 1
- Proposal: `TupleOf`
- Jsonify fails on nested object with name property. HOT 8
- Expose `UnknownRecord` in the public API HOT 2
- Expose `NonEmptyTuple` HOT 3
- `Destructurable` type
- Broken link on paka.dev in readme.md HOT 1
- Check if we need to reduce "excessively deep error" on WritableDeep too
- Support composable tagged types HOT 1
- SingleOrArray - Add type for a single value or an array of values
- Jsonify makes Record<string, any> disappear HOT 7
- Proposal: `Enumerate` and `IntRange` HOT 2
- Proposal: `IndexesOf` and `ItemsOf` HOT 2
- Missing export after adding `Tagged` type HOT 3
- SetParameterType for functions HOT 3
- Expose more internal types HOT 1
- `RequiredDeep` silently erases types past a depth of 3 as a side-effect HOT 2
- Add `Expand` type HOT 2
- `JsonObject` not limit object keys type HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from type-fest.