For example, the collection -
class Collection { insert(node){ } swap(a, b){ // в этом методе я должен обращаться // к свойствам node.someProps } } And with generics .ts it will be approximately like this
class Collection<T> { public insert<T>(node: T): void { } public swap<T>(a: T, b: T): void{ // в этом методе я должен обращаться // к свойствам node.someProps // !!! НО !!! } } ... BUT I can't do that, because type T no someProps property.
The question is how to make a dynamic collection with a base type that will have the necessary properties? Yes, and I would like to return the final type, not the base type.
Here is an example on TypeScript Playground .