Expose ArrayLength type#1344
Conversation
|
Strange, the IDE inferred |
som-sm
left a comment
There was a problem hiding this comment.
LGTM! Just few minor comments.
|
@jericirenej Updated the implementation of export type ArrayLength<T extends readonly unknown[]> = T['length'];
type T = ArrayLength<any>
//=> anyThe previous implementation returned type ArrayLength<T extends readonly unknown[]> = T extends {readonly length: infer L} ? L : never;
type T = ArrayLength<any>
//=> unknownAlso, the updated implementation is much simpler. |
|
@som-sm Looks great, thanks! 👍 This possibility of accessing the length directly was also one of the reasons that - when faced with the options to expose the type or remove it - I was leaning more into arguing for its omission in my initial post. |
I agree, this type isn’t that useful. It’s essentially just syntactic sugar, |
|
I think it's useful as documentation. It's easy to say that |
|
Ok, I'll update the base type description and docs later today! |
…e (determinable -> fixed)
Removed additional explanation for ArrayLength.
9245f0e to
6d4390d
Compare
|
Rebased to current Hopefully the added documentation is clear and concise enough: |
|
Is there anything else that needs to change here or is the current solution good enough for merging @sindresorhus? |
|
Thanks for working on this :) |
Issue #1341 proposed either deleting or exporting the unused
ArrayLengthinternal type.The issue was marked as a duplicate of #676 with the comment that exposing internal types is encouraged.
In this PR:
ArrayLengthis moved fromìnternal/array.d.tsto a separate file insource.