94function generateSizeAndCaches(item: TreeEntry): [number, string] {
95 if (item instanceof TreeDir) {
96 for (const subitem of item.children) {
97 if (subitem instanceof TreeDir) { 98 generateSizeAndCaches(subitem);
99 }
100 }
92}
93
94function generateSizeAndCaches(item: TreeEntry): [number, string] {
95 if (item instanceof TreeDir) { 96 for (const subitem of item.children) {
97 if (subitem instanceof TreeDir) {
98 generateSizeAndCaches(subitem);
81 }
82
83 isDirectory(): boolean {
84 return this instanceof TreeDir; 85 }
86
87 isFile(): boolean {
85 }
86
87 isFile(): boolean {
88 return this instanceof TreeFile; 89 }
90
91 abstract clone(parent?: TreeDir): TreeEntry;
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.
const knight: Radiant = {
order: "SurgeBinder"
strength: 30
}
interface Radiant {
order: string;
strength: number;
}
interface Radiant {
order: string;
strength: number;
}
const knight: Radiant = {
order: "SurgeBinder"
strength: 30
}