Examples
Invalid
// explicit return type is wider than what the function actually returns
function a(): string | number {
return "some string";
}
declare const v: 1 | 2;
function b(): 1 | 2 | 3 {
return v;
}
Valid
// explicit return type matches actual return
function a(): string {
return "some string";
}
declare const v: 1 | 2;
function b(): 1 | 2 {
return v;
}
Examples
Invalid
Valid