I have the following package my library having a class an interface exported.
src/Notification.ts
import {INotification} from 'INotification';
export class Notification implements INotification {
private readonly _name: string;
private _body?: any;
public constructor(name: string, body?: any) {
this._name = name;
this._body = body;
}
public get name(): string {
return this._name;
}
public get body(): any {
return this._body;
}
}
src/INotification
export interface INotification {
readonly name: string;
body?: any;
}
index.ts
export {Notification} from './src/Notification';
export type {INotification} from "./src/interfaces/INotification";
Project using my library
I manually copied mylibrary into node_modules folder
package.json
"dependencies": {
"react": "18.2.0",
"react-native": "0.71.19",
"mylibrary": "file:node_modules/mylibrary"
},
App.js
import {StyleSheet, Text, View} from 'react-native';
import React from 'react';
import {Notification} from 'my library';
const App = () => {
const n = new Notification('a', null);
return (
<View>
<Text>{n.name}</Text>
</View>
);
};
export default App;