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

264
Visualizações
How can you include inherited properties in type definitions generated from .js files by tsc?

I am trying to add typescript support to a vanilla javascript library via .d.ts files. I am trying to generate these type definition files with the "tsc" command, but I am running into many "property 'propertyName' does not exist on type 'typeName'" errors.

This is happening on lines that attempt to call a function on an instance of a child class when that function is defined only in the code for its parent class. It seems that while JSDoc is capable of inferring inherited functions by using "@extends" in the JSDoc comments of a child class, tsc is not.

For example:

ParentClass.js

/**
* This is the parent class.
* 
* @class
*/
export class ParentClass {
  parentFunction(){
    console.log("Running parent function");
  }
}

childClass.js

/**
* This is a child class.
* 
* @class
* @extends {ParentClass}
*/

import {ParentClass} from "./ParentClass";

class ChildClass extends ParentClass {
  // ChildClass vars and functions here
}

program.ts

import {ChildClass} from "./ChildClass";

let cc = new ChildClass();
cc.parentFunction();

Upon attempting to compile the code, tsc will throw this error:

error TS2339: Property 'parentFunction' does not exist on type 'ChildClass'.

Is there any way to resolve this issue? If there is no way to make the typescript compiler recognize inherited properties, is there some way to make tsc ignore this issue so it can at least finish generating the type definition files and allow me to manually add the missing properties to the corresponding child class type definitions?

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

0

You've forgotten to import the other files on the childClass.js and program.js. It should be something like this:


ParentClass.js

/**
* This is the parent class.
*
* @class
*/
export class ParentClass {
  parentFunction(){
    console.log("Running parent function");
  }
}

childClass.js

import { ParentClass } from './ParentClass'

/**
* This is a child class.
*
* @class
* @extends {ParentClass}
*/
export class ChildClass extends ParentClass {
  // ChildClass vars and functions here
}

program.js

import { ChildClass } from './childClass'

let cc = new ChildClass();
cc.parentFunction();
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