How could I restrict function param required in typescript?

Viewed 41
type cb = (str: string) => void

let demo1:cb=(str:string) => {return "anything"} //correct

let demo2:cb=(num:number) => {return "anything"} //error Type 'string' is not assignable to type 'number'.

let demo3:cb=() => {return "anything"} //correct, why?

demo here

I want to restrict the param not empty ,someting error like this:

let demo:cb=() => {return "anything"} //error , the param is required
0 Answers
Related