I have developed custom type definitions for a module called @xmpp/client
. Integrating these types into my TypeScript project has been challenging, as the compiler fails to recognize them.
My typings are stored in a directory named types
, resulting in the following folder structure:
.
├── app.json
├── App.tsx
├── package.json
├── src
│ └── <snip>
├── types
│ └── @xmpp
│ └── client.d.ts
├── tsconfig.json
└── yarn.lock
I have experimented with different folder structures, such as having types/@xmpp/client/index.d.ts
but none have been successful. Each time I compile, I encounter the error message
Cannot find module '@xmpp/client'
.
Here is an excerpt from my tsconfig.json
:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "react-native",
"lib": ["dom", "esnext"],
"moduleResolution": "node",
"noEmit": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"strictNullChecks": true,
"typeRoots": ["./node_modules/@types", "./types"]
},
"includes": ["src/**/*.{ts,tsx}", "types/**/*.d.ts"]
}
Could someone identify any issues with this configuration? Is my tsconfig.json
correct, and how should I organize my types
folder for a module with slashes in its name?
The custom type definitions are outlined below:
import { EventEmitter } from "react-native";
declare module "@xmpp/client" {
export function client(options: {
service?: string;
domain?: string;
resource?: string;
username?: string;
password?: string;
credentials?: (
auth: ({ username: string, password: string }) => any,
mechanism: string
) => any;
}): XmppClient;
type XmppClient = EventEmitter & {
start: () => void;
stop: () => void;
send: (...args: any) => Promise<any>;
};
export function jid(): any;
<snip>
}