Skip to content

🔥 [🐛] valueOf of function is misidentified as deprecated #9090

Description

@andrastoth-ws

Issue

I get deprecation warnings about valueOf function being deprecated and that I should use the equivalent modular API version of it. But that does not exist!

TS2614: Module '@react-native-firebase/firestore' has no exported member valueOf.

Now please excuse me for using an LLM for this but it managed to reproduce the issue in 2 distinct flavor (I've added a third one for Timestamp class myself.)

Minimal repro

// This is intro is by the LLM, below I have added my human comments - and of course I verified it myself.
// Bug: `createDeprecationProxy` (in @react-native-firebase/app/lib/common/index.ts) wraps
// the object returned by `getFirestore()` in a Proxy that looks up the accessed property name
// in a plain deprecation-map object (e.g. `{ batch: 'writeBatch()', collection: 'collection()', ... }`).
// Because every JS object inherits `Object.prototype.valueOf`, that lookup always finds a truthy
// "match" for the property name `valueOf` — even though `valueOf` was never intentionally added
// to the map — so accessing/calling `.valueOf` on ANY such wrapped object logs a false positive:
// "Method called was `valueOf`. Please use `function valueOf() { [native code] }` instead."
import { getFirestore } from '@react-native-firebase/firestore';
import React from 'react';
import { Button, View } from 'react-native';
import { Timestamp } from 'firebase/firestore';

export function ValueOfBugRepro() {
  function triggerExplicitValueOf() {
    const db = getFirestore();
    // `.valueOf()` exists on all objects therefore this is legit but triggers the warning
    console.log('[ValueOfBugRepro] explicit db.valueOf() ->', db.valueOf());

    // Timestamp is not changing to modular, so this is also a false positive IMO.
    const timestamp = new Timestamp(5000, 0);
    console.log('[ValueOfBugRepro] explicit timestamp valueOf ->', timestamp.valueOf());
  }

  function triggerImplicitValueOf() {
    const db: unknown = getFirestore();
    // This is a bit of an unhinged example but it also does trigger the warning.
    // No `.valueOf()` in sight - a plain relational comparison makes the JS engine
    // probe for `.valueOf` under the hood (ECMA-262 OrdinaryToPrimitive, hint "default").
    console.log('[ValueOfBugRepro] implicit coercion db > 0 ->', (db as number) > 0);
  }

  return (
    <View style={{ flexDirection: 'row', gap: 8, padding: 8 }}>
      <Button title="Repro: db.valueOf()" onPress={triggerExplicitValueOf} />
      <Button title="Repro: db > 0 (implicit)" onPress={triggerImplicitValueOf} />
    </View>
  );
}

package.json:

{
    "@react-native-firebase/analytics": "~23.8.6",
    "@react-native-firebase/app": "~23.8.6",
    "@react-native-firebase/auth": "~23.8.6",
    "@react-native-firebase/crashlytics": "~23.8.6",
    "@react-native-firebase/firestore": "~23.8.6",
    "@react-native-firebase/functions": "~23.8.6",
    "@react-native-firebase/in-app-messaging": "~23.8.6",
    "@react-native-firebase/installations": "~23.8.6",
    "@react-native-firebase/messaging": "~23.8.6",
    "@react-native-firebase/perf": "~23.8.6",
    "@react-native-firebase/remote-config": "~23.8.6",
    "@react-native-firebase/storage": "~23.8.6",
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions