Skip to content

Commit c9570df

Browse files
johnlindquistbenlesh
authored andcommitted
fix(isArrayLike): reject functions because functions have "length" (#3562)
* fix(isArrayLike): reject functions because functions have "length" * fix(isArrayLike): Undoing auto-formatting changes
1 parent 9217a03 commit c9570df

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

spec/observables/from-spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from 'chai';
22
import { TestScheduler } from 'rxjs/testing';
3-
import { asyncScheduler, of, from, Observable, asapScheduler, Observer } from 'rxjs';
3+
import { asyncScheduler, of, from, Observable, asapScheduler, Observer, observable, Subject } from 'rxjs';
4+
import { first } from 'rxjs/operators';
45

56
// tslint:disable:no-any
67
declare const asDiagram: any;
@@ -118,5 +119,26 @@ describe('from', () => {
118119
);
119120
expect(nextInvoked).to.equal(false);
120121
});
122+
it(`should accept a function`, (done) => {
123+
const subject = new Subject();
124+
const handler = (...args: any[]) => subject.next(...args);
125+
handler[observable] = () => subject;
126+
let nextInvoked = false;
127+
128+
from((handler as any)).pipe(first()).subscribe(
129+
(x) => {
130+
nextInvoked = true;
131+
expect(x).to.equal('x');
132+
},
133+
(x) => {
134+
done(new Error('should not be called'));
135+
},
136+
() => {
137+
expect(nextInvoked).to.equal(true);
138+
done();
139+
}
140+
);
141+
handler('x');
142+
});
121143
}
122144
});

src/internal/util/isArrayLike.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const isArrayLike = (<T>(x: any): x is ArrayLike<T> => x && typeof x.length === 'number');
1+
export const isArrayLike = (<T>(x: any): x is ArrayLike<T> => x && typeof x.length === 'number' && typeof x !== 'function');

0 commit comments

Comments
 (0)