Can typescript's checkjs validate a javascript class properly implements an Interface from a definition file?

Viewed 83

I have a project using jsdoc to annotate types and typescript's checkjs validates those types. I'd like to validate that a class properly implements an interface. I know I can use typescript declaration files to create an interface but I'm not clear on whether I can get checkjs to validate its usage:

// SomeInterface.d.ts
export interface SomeInterface { 
    public static aStaticFunction(): void
}
// @ts-check
/**
 * @extends {import('./SomeInterface').SomeInterface}
 */
class Foo {}

Is it possible to get typescript to complain about the class Foo not implementing aStaticFunction?

1 Answers

Try this

// @ts-check
/** @typedef {import('./SomeInterface').SomeInterface} MyInterface*/

/**
 * @implements {MyInterface}
 */
class Foo {}
Related