1

I've been stuck on a newbie problem: I have two projects, A and B, and a local module Lib that both A and B use. Everything's written in TypeScript.

A/
    package.json
B/
    package.json
Lib/
    package.json
    index.ts

Is there an example of this? This issue describes the problem... 2 years ago.

This answer describes four ways to solve this problem. I choose option 2, create an npm package, because it's the only one that lets me use modules in a sane way.

Here's the problem: The Lib module depends on a C.js file which I have written a C.d.ts file for.

Lib/
    package.json
    index.ts
    C.js
    C.d.ts

Where should I put the source TypeScript files? If I put all my pre-compiled sources into a Lib/src/ directory, then when I compile, C.d.ts and C.js aren't copied into the compiled directory, so type resolution fails. If I put my pre-compiled sources into the root Lib/ directory, then type resolution fails trying to read index.ts instead of index.d.ts.

What's the canonical example of bundling a TypeScript project for use w/ npm?

Community
  • 1
  • 1
Jamie
  • 2,181
  • 1
  • 21
  • 35

0 Answers0