Explicit types on the exported API
Rule
Every exported function and public method declares its parameter types and its return type. Internal helpers may rely on inference. The return type is part of the public contract; changing it is a SemVer decision, not a side effect of an edit.
Do
export function idf(totalDocs: number, docFreq: number): number {
return Math.log(1 + (totalDocs - docFreq + 0.5) / (docFreq + 0.5));
}Don’t
export function idf(totalDocs: number, docFreq: number) {
return Math.log(1 + (totalDocs - docFreq + 0.5) / (docFreq + 0.5));
}Rationale
Inferred return types let an implementation change silently widen or narrow the published API. explicit-module-boundary-types checks exported functions only, which matches this rule’s scope; explicit-function-return-type would also flag every internal callback.
Related
- STD-TS-006: what the declared return type carries for failures
- Rules