Source
https://www.typescriptlang.org/docs/handbook/2/generics.html
ClassA
and ClassB
both take string arguments during object creationgetClassInstance
has two parameters, one is a string parameter for object creation. The other is the class type for the constructorclass ClassA {
private myName: string;
constructor(name: string){
this.myName = name;
}
public get name(): string {
return this.myName;
}
}
class ClassB {
private myName: string;
constructor(name: string){
this.myName = name;
}
public get name(): string {
return this.myName;
}
public get currentDate(): Date {
return new Date();
}
}
function getClassInstance <Type>(newName: string, classType: { new (name: string): Type }): Type {
const classInstance = new classType(newName);
return classInstance;
}
const classAInstance = getClassInstance('testA', ClassA)
console.log(classAInstance.name);
const classBInstance = getClassInstance('testB', ClassB)
console.log(classBInstance.name);
typescript
generics
Vercel is an end-to-end platform for developers, that allows you to create and deploy your web application. Vercel provides the following features to enable you to serve fast and personalized content to your users:
Jun 17, 2023https://browsee.io/blog/chropath-a-quick-way-to-get-and-verify-xpath-and-css-selectors/
May 25, 2023https://docs.microsoft.com/en-us/sql/connect/jdbc/working-with-a-connection?view=sql-server-ver15
May 25, 2023https://www.sitepoint.com/bdd-javascript-cucumber-gherkin/ https://vinodmuralidharan.medium.com/cucumber-js-data-table-guide-a2447b74c86e Different between the data tables and Examples At least two columns .feature file Scenario: Category dropdown When the user navigates to the home page When the user selects a category from the category dropdown:
May 25, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up