typescript-class-types
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

Typescriptowe typy pomagające operować na klasach.

Typy Class AbstractClass

Przykłady

Bardzo podstawowe użycie:

import { Class } from "typescript-class-types";

function doSomethingWithClass(someClass: Class): void {
    //do something
}

class ExampleClass {

}

doSomethingWithClass(ExampleClass);

Wymaganie klasy z określonym interfejsem:

import { Class } from "typescript-class-types";

interface ExampleInterface {
    someMethod(): void;
}

function doSomethingWithClass(someClass: Class<ExampleInterface>): void {
    //do something
}

class ExampleClass implements ExampleInterface {
    public someMethod(): void {

    }
}

doSomethingWithClass(ExampleClass); //works correct, ExampleClass implements ExampleInterface interface

class SecondExampleClass {

}

doSomethingWithClass(SecondExampleClass); //TypeScript error, SecondExampleClass not implements ExampleInterface interface

Zamiana klasy abstrakcynej na zwykłą:

import { AbstractClass } from "typescript-class-types";

abstract class AbstractExampleClass {
    public someMethod(): void;
}

function transformAbstractClassIntoClass<T>(abstractClass: AbstractClass<T>): Class<T> {
    const class: Class<T> = /* some logic to transform abstract class into class */;
    return class;
}

const exampleClass = transformAbstractClassIntoClass(AbstractExampleClass);
const example = new exampleClass(); //works correct, can create instance on non-abstract class

Injektor

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.24latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.24
1.2.11
1.2.01
1.1.01
1.0.113
1.0.101
1.0.91
1.0.81
1.0.71
1.0.61
1.0.51
1.0.41
1.0.31
1.0.21
1.0.11
1.0.00

Package Sidebar

Install

npm i typescript-class-types

Weekly Downloads

20

Version

1.2.2

License

ISC

Unpacked Size

12.4 kB

Total Files

26

Last publish

Collaborators

  • swojdyga