Typescript: Function Types

I tried a few examples in the typescript reference. More specifically, I came across function types.

interface SearchFunc {
    (source: string, subString: string): boolean;
}

interface SearchFunc {
  (source: string, subString: string): boolean;
}

var mySearch: SearchFunc;

mySearch = function(subString: string) {
    var result = 1;
    if (result == -1) {
        return false;
    }
    else {
        return true;
    }
}

I wonder why the above does not show me any errors. mySearchclearly does not match the signature declared in the interface.

+4
source share

Source: https://habr.com/ru/post/1621607/


All Articles