Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!