Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Accept numbers and booleans in `withEnvironment`

Aperta
#1,543 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, node.js, typescript
Ambito
testing, tooling

Direzione di ricerca

Read packages/testcontainers/src/types.ts and trace how Environment is consumed by the two withEnvironment methods and exec's env option. Check how subclasses access the protected environment field, then review the related issue #1519 because both changes rewrite withEnvironment. Done means accepting string, number, boolean, and undefined values while stored environment values remain strings and undefined keys are skipped.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement minor

What happens

Environment is { [key: string]: string }, so every non-string value has to be converted at the call site:

.withEnvironment({
  PORT: String(port),
  MAX_CONNECTIONS: maxConnections.toString(),
  DEBUG: "true",
})

Optional values need a conditional spread to avoid passing undefined:

.withEnvironment({ ...(token ? { TOKEN: token } : {}) })

The same type is used by DockerComposeEnvironment.withEnvironment and by exec's env option.

Expected

withEnvironment accepts string | number | boolean values and converts them, and skips keys whose value is undefined:

.withEnvironment({ PORT: port, DEBUG: true, TOKEN: token })

Where

  • Environment in packages/testcontainers/src/types.ts
  • withEnvironment in packages/testcontainers/src/generic-container/generic-container.ts
  • withEnvironment in packages/testcontainers/src/docker-compose-environment/docker-compose-environment.ts

Notes

  • Widening the accepted type is compatible for callers. Subclasses that read the protected environment field should keep seeing strings.
  • Related: #1519 (duplicate entries when a key is set twice).

Dependencies

  • Stack on #1519: both rewrite withEnvironment.
Lingua principale
TypeScript
Stelle
2.6k
Fork
274
Merge medio
1g 14h
PR unite (30g)
44

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-node

Tutte le issue di testcontainers/testcontainers-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.