Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

504
Visualizações
Possible to change the TypeScript interface for built in JavaScript object (JSON)?

JSON.strigify() breaks with cyclic objects (as per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value )

The same article recommends 'cycle.js' - which adds 2 methods to the global JSON object - .decycle() & .retrocycle() to stringify cyclic objects.

This works great, but typescript complains unless I add

//@ts-ignore

or other ts hacks - JSON [ 'retrocycle' ] (), etc - which I can do but it's not pretty.

Is there anyway to create something like a "JSON.d.ts" file to override the default TS interface for the global JSON object?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not sure why this was closed & then re-opened - but by putting together several threads, I came up with this - in case anyone else is interested:

Create a .d.ts typefile, say in src/custom_types:

src/custom_types/JSON.d.ts

In JSON.d.ts:

export declare global {
    interface JSON {
            decycle(object: any, replacer?: any): string;
            retrocycle(something: any): any;
    }
}

In tsconfig.json:

{
  "compilerOptions": {
    ...
    "baseUrl": ".",
    ...
    "paths" : {
      ...
    "*" : ["src/custom_types/*"],
    }
  },
  "typeRoots": [
    ....
    "src/custom_types/",
    ],
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda