Skip to content

Remove ArrayLike from ObservableInput #6011

Closed

Description

@benlesh

Related to this issue here: #4563

The problem is that this is true:

const x: ArrayLike<any> = () => {}

But at runtime, our check makes sure it's not a function:

export const isArrayLike = (<T>(x: any): x is ArrayLike<T> => 
    x && typeof x.length === 'number' && typeof x !== 'function');

This, combined with the fact that any "array-like" I know of has implemented Symbol.iterator now, means that this type is mostly worthless. I doubt many people are like:

const source$ = from({
   length: 2,
   "0": "wee",
   "1": "I'm weird!"
})

Activity

  1. added
    AGENDA ITEM
    on Feb 9, 2021
  2. benlesh commented on Feb 9, 2021

    @benlesh
    MemberAuthor

    Okay, this gets weirder and weirder... in TS 4.1.3:

    interface ArrayLike<T> {
        readonly length: number;
        // readonly 0: T;
        readonly [n: number]: T;
    }
    
    function works(arg: ArrayLike<any>) {}
    
    works(() => {});
    
    function doesNotWork<T>(arg: ArrayLike<T>) { }
    
    doesNotWork(() => {});

    I'm not totally sure what to make of that... playground here

  3. cartant commented on Feb 9, 2021

    @cartant
    Collaborator

    Related TS issue: microsoft/TypeScript#18757

  4. benlesh commented on Feb 10, 2021

    @benlesh
    MemberAuthor

    We probably shouldn't do this for now... this PR in TypeScript is of interest: microsoft/TypeScript#41660

  5. removed
    AGENDA ITEM
    on Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy