Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript strict mode doesn't work without manually adding @types/dockerode as dependency #667

Closed
tyilo opened this issue Nov 2, 2023 · 1 comment · Fixed by #679
Closed
Labels
bug Something isn't working

Comments

@tyilo
Copy link

tyilo commented Nov 2, 2023

Expected Behaviour
TypeScript strict mode works out of the box.

Actual Behaviour
@types/dockerode needs to be manually added as a dependency. (This seems to be the same issues as in #77)

Testcontainer Logs
Not relevant

Steps to Reproduce

$ mkdir /tmp/repro
$ cd /tmp/repro
$ npm init -y
$ npm add typescript
$ npm add @testcontainers/mongodb
$ cat > test.ts
import { GenericContainer } from "testcontainers";
console.log(GenericContainer);
^D
$ npx tsc --strict --esModuleInterop test.ts
node_modules/testcontainers/build/container-runtime/clients/container/container-client.d.ts:3:130 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

3 import Dockerode, { Container, ContainerCreateOptions, ContainerInfo, ContainerInspectInfo, ContainerLogsOptions, Network } from "dockerode";
                                                                                                                                   ~~~~~~~~~~~

node_modules/testcontainers/build/container-runtime/clients/image/image-client.d.ts:1:35 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

1 import { ImageBuildOptions } from "dockerode";
                                    ~~~~~~~~~~~

node_modules/testcontainers/build/container-runtime/clients/network/network-client.d.ts:1:47 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

1 import { Network, NetworkCreateOptions } from "dockerode";
                                                ~~~~~~~~~~~

node_modules/testcontainers/build/generic-container/generic-container.d.ts:7:52 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

7 import { ContainerCreateOptions, HostConfig } from "dockerode";
                                                     ~~~~~~~~~~~

node_modules/testcontainers/build/generic-container/started-generic-container.d.ts:4:49 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

4 import Dockerode, { ContainerInspectInfo } from "dockerode";
                                                  ~~~~~~~~~~~

node_modules/testcontainers/build/network/network.d.ts:1:23 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

1 import Dockerode from "dockerode";
                        ~~~~~~~~~~~

node_modules/testcontainers/build/wait-strategies/composite-wait-strategy.d.ts:2:23 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

2 import Dockerode from "dockerode";
                        ~~~~~~~~~~~

node_modules/testcontainers/build/wait-strategies/http-wait-strategy.d.ts:1:23 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

1 import Dockerode from "dockerode";
                        ~~~~~~~~~~~

node_modules/testcontainers/build/wait-strategies/log-wait-strategy.d.ts:1:23 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

1 import Dockerode from "dockerode";
                        ~~~~~~~~~~~

node_modules/testcontainers/build/wait-strategies/shell-wait-strategy.d.ts:1:23 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

1 import Dockerode from "dockerode";
                        ~~~~~~~~~~~

node_modules/testcontainers/build/wait-strategies/startup-check-strategy.d.ts:2:23 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

2 import Dockerode from "dockerode";
                        ~~~~~~~~~~~

node_modules/testcontainers/build/wait-strategies/wait-strategy.d.ts:1:23 - error TS7016: Could not find a declaration file for module 'dockerode'. '/tmp/repro/node_modules/dockerode/lib/docker.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/dockerode` if it exists or add a new declaration (.d.ts) file containing `declare module 'dockerode';`

1 import Dockerode from "dockerode";
                        ~~~~~~~~~~~


Found 12 errors in 12 files.

Errors  Files
     1  node_modules/testcontainers/build/container-runtime/clients/container/container-client.d.ts:3
     1  node_modules/testcontainers/build/container-runtime/clients/image/image-client.d.ts:1
     1  node_modules/testcontainers/build/container-runtime/clients/network/network-client.d.ts:1
     1  node_modules/testcontainers/build/generic-container/generic-container.d.ts:7
     1  node_modules/testcontainers/build/generic-container/started-generic-container.d.ts:4
     1  node_modules/testcontainers/build/network/network.d.ts:1
     1  node_modules/testcontainers/build/wait-strategies/composite-wait-strategy.d.ts:2
     1  node_modules/testcontainers/build/wait-strategies/http-wait-strategy.d.ts:1
     1  node_modules/testcontainers/build/wait-strategies/log-wait-strategy.d.ts:1
     1  node_modules/testcontainers/build/wait-strategies/shell-wait-strategy.d.ts:1
     1  node_modules/testcontainers/build/wait-strategies/startup-check-strategy.d.ts:2
     1  node_modules/testcontainers/build/wait-strategies/wait-strategy.d.ts:1

Adding @types/dockerode manually fixes the problem:

$ npm add @types/dockerode
$ npx tsc --strict --esModuleInterop test.ts

Environment Information

  • Operating System: Not relevant
  • Docker Version: Not relevant
  • Node version: 20.9.0
  • Testcontainers version: 10.2.2
@cristianrgreco cristianrgreco added triage Investigation required bug Something isn't working and removed triage Investigation required labels Nov 23, 2023
@cristianrgreco
Copy link
Collaborator

Thanks for raising @tyilo, will release the fix shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants