Hi! After upgrading to [email protected], I started getting a runtime error when using named imports.
Example
import { getAllWithoutPhotos } from 'react-native-contacts';
const allContacts = await getAllWithoutPhotos();
Runtime error
TypeError: undefined is not a function
What seems to be happening
The TypeScript definitions expose named exports in index.d.ts:
export function getAllWithoutPhotos(): Promise<Contact[]>;
export function getAll(): Promise<Contact[]>;
But the actual index.ts only exports these methods inside the default export object:
export default {
getAll,
getAllWithoutPhotos,
...
};
Because of this, TypeScript accepts the named import, but at runtime getAllWithoutPhotos is undefined.
Workaround
Using the default export works:
import Contacts from 'react-native-contacts';
const allContacts = await Contacts.getAllWithoutPhotos();
Expected behavior
The TypeScript declarations should match the runtime API.
Either:
- add real named exports in
index.ts, or
- update the TypeScript declarations/docs to only expose the default export API.
Environment
react-native-contacts: 8.0.10
react-native: 0.83.6
Thanks!
Hi! After upgrading to
[email protected], I started getting a runtime error when using named imports.Example
Runtime error
What seems to be happening
The TypeScript definitions expose named exports in
index.d.ts:But the actual
index.tsonly exports these methods inside the default export object:Because of this, TypeScript accepts the named import, but at runtime
getAllWithoutPhotosisundefined.Workaround
Using the default export works:
Expected behavior
The TypeScript declarations should match the runtime API.
Either:
index.ts, orEnvironment
react-native-contacts:8.0.10react-native:0.83.6Thanks!