Skip to content

Update library to use declare class #55611

@james-pre

Description

@james-pre

Currently, declarations for classes consist of an interface for the instance and a declare var for the static side. This is a convoluted way of approaching classes. Instead, Typescript should use declare class, which clarifies the type (since the class is known to be a class, rather than a var object which has a new method and prototype property) and simplifies the definition (only one declaration).

Sample Code

// old
interface Class {
	method(): void;
	property: number;
}

declare var Class: {
	prototype: Class;
	new(arg: string): Class;
	staticMethod(): void;
}

//new
declare class Class {
	method(): void;
	property: number;
	constructor(arg: string);
	static staticMethod(): void;
}

Documentation Link

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions