void as a type of an argument of a generic function in TypeScript

前端 未结 7 1290
遥遥无期
遥遥无期 2021-01-11 09:37

It is possible to specify void as a type parameter for generic function in TypeScript. And it works fine for return values of functions. However when void

7条回答
  •  春和景丽
    2021-01-11 10:03

    You can do something like this:

    class Example {
        process(func: T = undefined) {
        // use default undefined parameter
        }
    }
    
    var example = new Example();
    
    exmple.process();
    

    I'm using Typescript 1.8.7 and it worked for me fine.

提交回复
热议问题