Skip to content

Question: How to get the the generic type of Array? #262

Closed
@LiaoPeng

Description

@LiaoPeng

The requirement is to create obj by generic type.

class A { }
function createObj<T>(): T {
    var isArr = isArray<T>();
    if (isArr) {
        let arr = {} as T;
        // Is there a way to create an instance of A and push the instance to the `arr`
       return arr;
    }
    // other logic
}
createObj<Array<A>>();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions