Reputation: 378
I'm creating a package in typescript and I generate the declaration files using the tsc tool but when I try to import this package from another project type definitions doesn't load automatically and I get type errors. How can I achieve this problem? I know there are modules that you don't need to install or specify typings to use but I couldn't find how to do this.
EDIT - details: I generate declaration file using the tsc --declarations
command and all of them goes directly to the build directory with js files. I've {"types": "./build/index.d.ts", "typescript.tsdk": "./build"}
in my package.json but it doesn't seem to effect anything. Here are some examples:
build/index.d.ts
import Network from './network';
import Queue from './queue';
export { Queue, Network, Jobs };
build/network/index.d.ts
import Address from './address';
import Socket from './socket';
import Packet from './packet';
export { Address, Socket, Packet };
declare var _default: {
Address: typeof Address;
Socket: typeof Socket;
Packet: typeof Packet;
};
export default _default;
build/network/packet.dt.ts
export default class Packet {
private params;
static fromString(str: string): Packet;
toString(): string;
}
Upvotes: 1
Views: 234
Reputation: 105547
Since you use default export and your package is inside node_modules
, you can import it the following way:
import Socket from "core/build/network/socket";
class Abc extends Socket {
constructor() {
super();
this.connect('address');
}
}
let s = new Socket();
s.connect('address');
Upvotes: 1