Skip to content

Remove ArrayLike from ObservableInput #6011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
benlesh opened this issue Feb 9, 2021 · 3 comments
Closed

Remove ArrayLike from ObservableInput #6011

benlesh opened this issue Feb 9, 2021 · 3 comments

Comments

@benlesh
Copy link
Member

benlesh commented Feb 9, 2021

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!"
})
@benlesh benlesh added the AGENDA ITEM Flagged for discussion at core team meetings label Feb 9, 2021
@benlesh
Copy link
Member Author

benlesh commented Feb 9, 2021

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

@cartant
Copy link
Collaborator

cartant commented Feb 9, 2021

Related TS issue: microsoft/TypeScript#18757

@benlesh
Copy link
Member Author

benlesh commented Feb 10, 2021

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

@benlesh benlesh closed this as completed Feb 10, 2021
@benlesh benlesh removed the AGENDA ITEM Flagged for discussion at core team meetings label Feb 10, 2021
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

No branches or pull requests

2 participants