TypeScript
TypeScript copied to clipboard
Add setting to exclude constructors from definition list
I am writing a Playwright test suite in TypeScript using VSCode. We are following a standard pattern of using classes wrapped around a Playwright page object that abstract common workflows. For convenience we have created an extremely basic base class that all other classes are extending, which allows us to do inline property definition and omit constructors from the other classes entirely.
export class PageWrapper {
constructor(protected readonly page: Page) {}
}
export class LoginPage extends PageWrapper {
readonly email = this.page.getByLabel('Email')
readonly password = this.page.getByLabel('Password')
/* More code here */
}
However, when trying to jump to the class from where we're defining it within test code (like below), VSCode prioritises jumping to the dummy constructor of PageWrapper
instead of the actual class of LoginPage
(though will still show both in the definitions list).
const loginPage = new LoginPage(page)
I understand the logic behind this behaviour (since this is technically an invocation of the PageWrapper
constructor function), but in an ES6+ codebase I think the constructor definition is less important than the class definition. After all, if we needed to see the constructor code in this instance, we can follow the class dependency chain down to the invoked constructor.
I propose a new setting that allows constructors from being excluded from the definitions list when jumping to definition from a constructor invocation. I don't know whether a setting like this is necessary for languages other than JavaScript, or if this behaviour is just a byproduct of how JavaScript internally treats constructors.