Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
What's the proper way to fix this type error?

What's the proper way to fix this? I don't want to just cast or make a copy of the array, converting undefined to an empty string or something like this. I guess it's hacky. What's the proper way to fix this?

Type 'ProcessEnv' is not assignable to type '{ [key: string]: string; }'.
  'string' index signatures are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.ts(2322)
node-pty.d.ts(45, 5): The expected type comes from property 'env' which is declared here on type 'IPtyForkOptions | IWindowsPtyForkOptions'

code:

import { IPty, spawn } from 'node-pty';

    ptyProcess = spawn(shell, [], {
      name: 'xterm-color',
      cols: 80,
      rows: 30,
      cwd: process.env.HOME,
      env: process.env // error comes from this assignment
    });

EDIT 1:

Currently I'm doing this:

interface INonUndefinedEnv {
  [key: string]: string
}

const safeEnv = () => {
  let o:INonUndefinedEnv = {};
  for(const [key, value] of Object.keys(process.env).entries())
      o[key] = value ?? ""; // make sure it's string and never undefined
  return o;
}

then I can do:

ptyProcess = spawn(shell, [], {
  name: 'xterm-color',
  cols: 80,
  rows: 30,
  cwd: process.env.HOME,
  env: safeEnv() // type match
});

But I'd like to avoid all this loop if possible...

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I think the way you did it is not hacky. It's the right thing to do. The hacky thing to do would be to look into node-pty's source code to see if undefined values could cause an issue and using "as any" if they couldn't. :)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Based on the interface and the error given you would need to do this:

    import { IPty, spawn } from 'node-pty';

    ptyProcess = spawn(shell, [], {
      name: 'xterm-color',
      cols: 80,
      rows: 30,
      cwd: process.env.HOME,
      env: { myEnv: process.env }
    });

And you could change "myEnv" to whatever.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda