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

133
Vistas
Console log an interface without some object

Do you know how can I console log the interface example without the m and n? Below the two interface is in one file.

export interface example {
  readonly a: string;
  readonly b: F | undefined;
  readonly c: G | undefined;
  readonly d?: boolean;
  readonly e: H | undefined;
}
export interface F {
  readonly i: string;
  readonly j: q;
  readonly k: string | undefined;
  readonly l: r;
  readonly m: s | undefined;
  readonly n: t | undefined;
  readonly o: y | undefined;
  readonly p: v[] | undefined;
}

Below is in another file

import { example } from 'src/modules/ex';

exampleInfo: example | undefined;
console.log( exampleInfo.a + exampleInfo.b.i + exampleInfo.b.j + exampleInfo.b.k + exampleInfo.b.l + exampleInfo.b.o + exampleInfo.b.p + exampleInfo.c + exampleInfo.d+ exampleInfo.e)

Currently the console log is super long and easy to make mistake. Also I want to include the key(a,b,c,o,p...etc).not just the value. If I simply type

console.log(exampleInfo);

I can get the result I want (with all key and value pair). However, it's included the m&n that I don't want.

I've also tried to destruct it.

const {m,n, ...otherChar} = exampleInfo;

But it gives me error:

"Property 'm' does not exist on type 'example | undefined'.

Or

const {F.m,F.n, ... otherChar} = exampleInfo;

But still error:

 "Property 'F' does not exist on type 'example | undefined'.

Also tried this:

const {m,n, …otherChar} = exampleInfo.b;

Error changed to:

Property 'm' does not exist on type 'F | undefined'. 

How should I destruct it? or is there any other way to log them??

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

0

Try console.log(JSON.stringify(example))

MDN Web Docs

Edit

Sorry I didn't see the requirement clearly. Not sure this is optimal solution, but hope it helps.

let b = Object.fromEntries(Object.entries(example.b).filter(x => x[0] != 'm' && x[0] != 'n'));
const result = {...example};
result.b = b;
console.log(JSON.stringify(result));
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