'tryCall_' was used before it was defined
8 return new Promise((_resolve, reject) => reject(data));
9}
10
11export const tryCall = tryCall_;12
13var tryCall_ = async function <T>(
14 func: () => Promise<T>
Description
Variables, functions and types should always be used after they've been defined. This issue will flag any code snippets that use variables or types before definition.
Sometimes, the code will run just fine even when the variable is declared after use. Consider the following example:
const ram: Resource = { type: "memory", limit: 1024 ** 3 }
type Resource = {
type: string;
limit: number;
}
Here, Resource
is used in the annotation before it has been defined.
Similarly, it is possible to hoist function declarations and variables declared with the var
keyword:
const four = twice(2);
function twice(n: number) {
return n * 2;
}
However, it makes the code harder to follow when variables or types are declared after being used.
Bad Practice
const knight: Radiant = {
order: "SurgeBinder"
strength: 30
}
interface Radiant {
order: string;
strength: number;
}
Recommended
interface Radiant {
order: string;
strength: number;
}
const knight: Radiant = {
order: "SurgeBinder"
strength: 30
}