Skip to content

Commit 9695fa4

Browse files
committed
Fix isNumber implementation
1 parent b78e49c commit 9695fa4

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

packages/firestore/src/lite-api/pipeline.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { isNumber } from 'util';
19-
2018
import {
2119
Pipeline as ProtoPipeline,
2220
Stage as ProtoStage
@@ -29,7 +27,7 @@ import {
2927
selectablesToMap,
3028
vectorToExpr
3129
} from '../util/pipeline_util';
32-
import { isString } from '../util/types';
30+
import { isNumber, isString } from '../util/types';
3331

3432
import { Firestore } from './database';
3533
import {
@@ -544,10 +542,15 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
544542
offset(options: OffsetStageOptions): Pipeline;
545543
offset(offsetOrOptions: number | OffsetStageOptions): Pipeline {
546544
// Process argument union(s) from method overloads
547-
const options = isNumber(offsetOrOptions) ? {} : offsetOrOptions;
548-
const offset: number = isNumber(offsetOrOptions)
549-
? offsetOrOptions
550-
: offsetOrOptions.offset;
545+
let options: {};
546+
let offset: number;
547+
if (isNumber(offsetOrOptions)) {
548+
options = {};
549+
offset = offsetOrOptions;
550+
} else {
551+
options = offsetOrOptions;
552+
offset = offsetOrOptions.offset;
553+
}
551554

552555
// Create stage object
553556
const stage = new Offset(offset, options);

packages/firestore/src/util/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export function isNegativeZero(value: number): boolean {
3737
return value === 0 && 1 / value === 1 / -0;
3838
}
3939

40+
export function isNumber(value: unknown): value is number {
41+
return typeof value === 'number';
42+
}
43+
4044
/**
4145
* Returns whether a value is an integer and in the safe integer range
4246
* @param value - The value to test for being an integer and in the safe range

packages/firestore/test/integration/api/pipeline.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,8 +2823,7 @@ apiDescribe.only('Pipelines', persistence => {
28232823
});
28242824
});
28252825

2826-
// TODO re-enabled on fix of b/446938511
2827-
it.skip('array contains any', async () => {
2826+
it('array contains any', async () => {
28282827
const snapshot = await execute(
28292828
firestore
28302829
.pipeline()
@@ -3984,6 +3983,7 @@ apiDescribe.only('Pipelines', persistence => {
39843983
describe('stage options', () => {
39853984
describe('forceIndex', () => {
39863985
// SKIP: requires pre-existing index
3986+
// eslint-disable-next-line no-restricted-properties
39873987
it.skip('Collection Stage', async () => {
39883988
const snapshot = await execute(
39893989
firestore.pipeline().collection({
@@ -3995,6 +3995,7 @@ apiDescribe.only('Pipelines', persistence => {
39953995
});
39963996

39973997
// SKIP: requires pre-existing index
3998+
// eslint-disable-next-line no-restricted-properties
39983999
it.skip('CollectionGroup Stage', async () => {
39994000
const snapshot = await execute(
40004001
firestore.pipeline().collectionGroup({

0 commit comments

Comments
 (0)