docker-compose icon indicating copy to clipboard operation
docker-compose copied to clipboard

Docker-Compose V2 && ESM + TypeScript

Open jd-carroll opened this issue 1 year ago • 4 comments
trafficstars

I am attempting to use docker-compose in an ESM module with typescript. My preference is to use the forth coming v2 version so my import definition looks like:

import compose from 'docker-compose/dist/v2';

However, TypeScript is giving me the error:

Cannot find module 'docker-compose/dist/v2' or its corresponding type declarations.ts(2307)

I see the types in the distribution at node_modules/docker-compose/dist/v2.d.ts but those types do not expand the "module" definition.

Meaning, updating my tsconfig.json to be something like:

{
  "include": [
    "**/*.ts",
    "../../node_modules/docker-compose/dist/v2.d.ts"
  ],
}

Does not fix the issue, because the v2.d.ts does not tell TypeScript something lives at "dist/v2".

What is the best way to import the types for v2?

jd-carroll avatar May 09 '24 17:05 jd-carroll

Can you please share your Node.js and Typescript versions and your complete tsconfig?

AlexZeitler avatar May 09 '24 17:05 AlexZeitler

node 20.12

{
  "compilerOptions": {
    "moduleResolution": "NodeNext",
    "module": "NodeNext",
    "target": "ESNext",
    "isolatedModules": true,
    "lib": [
      "ESNext"
    ],
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "inlineSourceMap": false,
    "inlineSources": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "sourceMap": true,
    "skipLibCheck": true
  }
}

jd-carroll avatar May 09 '24 19:05 jd-carroll

Note: I think the v2.d.ts needs something like:

declare module 'docker-compose/dist/v2' {
  ...
}

Then it would be possible to do the following in the tsconfig.json:

{
  "include": [
    "**/*.ts",
    "../../node_modules/docker-compose/dist/v2.d.ts"
  ],
}

But I'm certainly no expert on this

jd-carroll avatar May 09 '24 20:05 jd-carroll

I'm working on it at #277 but it doesn't work yet (e.g. 0.24.9-alpha.4).

AlexZeitler avatar May 10 '24 13:05 AlexZeitler