Skip to content

Commit 5d2bb4c

Browse files
authored
refactor(examples): Add missing function return types (#26003)
In preparation for globally enabling an eslint rule that requires them.
1 parent 4e0431a commit 5d2bb4c

File tree

47 files changed

+263
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+263
-202
lines changed

examples/apps/staging/src/container/groceryList/groceryList.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class GroceryList implements IGroceryList {
7474
}
7575
}
7676

77-
public readonly addItem = (name: string) => {
77+
public readonly addItem = (name: string): void => {
7878
// Use timestamp as a hack for a consistent sortable order.
7979
this.map.set(`${Date.now()}-${uuid()}`, name);
8080
};
@@ -85,11 +85,11 @@ class GroceryList implements IGroceryList {
8585
);
8686
};
8787

88-
public readonly removeItem = (id: string) => {
88+
public readonly removeItem = (id: string): void => {
8989
this.map.delete(id);
9090
};
9191

92-
private readonly onMapValueChanged = (changed: IValueChanged) => {
92+
private readonly onMapValueChanged = (changed: IValueChanged): void => {
9393
const changedId = changed.key;
9494
const newName = this.map.get(changedId);
9595
if (newName === undefined) {

examples/apps/staging/src/container/suggestionGroceryList.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
4040
*/
4141
private readonly _suggestionGroceryItems = new Map<string, SuggestionGroceryItem>();
4242
private _inStagingMode = false;
43-
public get inStagingMode() {
43+
public get inStagingMode(): boolean {
4444
return this._inStagingMode;
4545
}
4646

@@ -86,7 +86,7 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
8686
}
8787
}
8888

89-
public readonly addItem = (name: string) => {
89+
public readonly addItem = (name: string): void => {
9090
if (this._inStagingMode) {
9191
// Use timestamp as a hack for a consistent sortable order. Prefixed with 'z' to sort last.
9292
const suggestedAddition = new SuggestionGroceryItem(
@@ -116,7 +116,7 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
116116
);
117117
};
118118

119-
public readonly removeItem = (id: string) => {
119+
public readonly removeItem = (id: string): void => {
120120
if (this._inStagingMode) {
121121
const suggestedRemoval = this._suggestionGroceryItems.get(id);
122122
if (suggestedRemoval !== undefined) {
@@ -133,8 +133,8 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
133133
}
134134
};
135135

136-
public readonly getSuggestions = () => {
137-
const asyncGetSuggestions = async () => {
136+
public readonly getSuggestions = (): void => {
137+
const asyncGetSuggestions = async (): Promise<void> => {
138138
const { adds, removals } = await getChangesFromHealthBot(this.groceryList);
139139
// Check to make sure we are still in staging mode after we get the results - if not, then just
140140
// discard the suggestions. Alternatively, we could wait for the network call to return before
@@ -154,7 +154,7 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
154154
asyncGetSuggestions().catch(console.error);
155155
};
156156

157-
public readonly acceptSuggestions = () => {
157+
public readonly acceptSuggestions = (): void => {
158158
const adds = [...this._suggestionGroceryItems.values()].filter(
159159
(item) => item.suggestion === "add",
160160
);
@@ -175,7 +175,7 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
175175
this._events.emit("leaveStagingMode");
176176
};
177177

178-
public readonly rejectSuggestions = () => {
178+
public readonly rejectSuggestions = (): void => {
179179
for (const item of this._suggestionGroceryItems.values()) {
180180
if (item.suggestion === "add") {
181181
item.removeItem();
@@ -188,7 +188,7 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
188188
this._events.emit("leaveStagingMode");
189189
};
190190

191-
private readonly onItemAdded = (item: IGroceryItem) => {
191+
private readonly onItemAdded = (item: IGroceryItem): void => {
192192
const addedItem = new SuggestionGroceryItem(
193193
item.id,
194194
item.name,
@@ -207,7 +207,7 @@ export class SuggestionGroceryList implements ISuggestionGroceryList {
207207
this._events.emit("itemAdded", addedItem);
208208
};
209209

210-
private readonly onItemRemoved = (item: IGroceryItem) => {
210+
private readonly onItemRemoved = (item: IGroceryItem): void => {
211211
const removedItem = this._suggestionGroceryItems.get(item.id);
212212
this._suggestionGroceryItems.delete(item.id);
213213
this._events.emit("itemRemoved", removedItem);

examples/apps/staging/src/start.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import {
2424
} from "./container/index.js";
2525
import { AppView, DebugView } from "./view/index.js";
2626

27-
const updateTabForId = (id: string) => {
27+
const updateTabForId = (id: string): void => {
2828
// Update the URL with the actual ID
2929
location.hash = id;
3030

3131
// Put the ID in the tab title
3232
document.title = id;
3333
};
3434

35-
const render = (groceryList: ISuggestionGroceryList) => {
35+
const render = (groceryList: ISuggestionGroceryList): void => {
3636
const appDiv = document.getElementById("app") as HTMLDivElement;
3737
const appRoot = createRoot(appDiv);
3838
appRoot.render(createElement(AppView, { groceryList }));

examples/apps/staging/src/view/appView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export interface IAppViewProps {
1313
groceryList: ISuggestionGroceryList;
1414
}
1515

16-
export const AppView: FC<IAppViewProps> = ({ groceryList }: IAppViewProps) => {
16+
export const AppView: FC<IAppViewProps> = ({ groceryList }: IAppViewProps): JSX.Element => {
1717
const [inStagingMode, setInStagingMode] = useState<boolean>(groceryList.inStagingMode);
1818

1919
useEffect(() => {
20-
const handleStagingModeChanged = () => {
20+
const handleStagingModeChanged = (): void => {
2121
setInStagingMode(groceryList.inStagingMode);
2222
};
2323
groceryList.events.on("enterStagingMode", handleStagingModeChanged);
@@ -30,10 +30,10 @@ export const AppView: FC<IAppViewProps> = ({ groceryList }: IAppViewProps) => {
3030

3131
let actions;
3232
if (inStagingMode) {
33-
const onAcceptChanges = () => {
33+
const onAcceptChanges = (): void => {
3434
groceryList.acceptSuggestions();
3535
};
36-
const onRejectChanges = () => {
36+
const onRejectChanges = (): void => {
3737
groceryList.rejectSuggestions();
3838
};
3939
actions = (

examples/apps/staging/src/view/groceryListView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ interface IAddItemViewProps {
4646
readonly addItem: (name: string) => void;
4747
}
4848

49-
const AddItemView: FC<IAddItemViewProps> = ({ addItem }: IAddItemViewProps) => {
49+
const AddItemView: FC<IAddItemViewProps> = ({ addItem }: IAddItemViewProps): JSX.Element => {
5050
const nameRef = useRef<HTMLInputElement>(null);
5151

52-
const onAddItemButtonClick = () => {
52+
const onAddItemButtonClick = (): void => {
5353
if (nameRef.current === null) {
5454
throw new Error("Couldn't get the new item info");
5555
}
@@ -91,7 +91,7 @@ export const GroceryListView: FC<IGroceryListViewProps> = ({
9191
groceryList.getItems(),
9292
);
9393
useEffect(() => {
94-
const updateItems = () => {
94+
const updateItems = (): void => {
9595
// TODO: This blows away all the grocery items, making the granular add/delete events
9696
// not so useful. Is there a good way to make a more granular change?
9797
setGroceryItems(groceryList.getItems());

examples/benchmarks/odspsnapshotfetch-perftestapp/src/fetchApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { MockLogger } from "@fluidframework/telemetry-utils/internal";
1111

1212
import { OdspSampleCache } from "./odspPersistantCache.js";
1313

14-
export function start(div: HTMLDivElement, odspAccessToken: string) {
14+
export function start(div: HTMLDivElement, odspAccessToken: string): void {
1515
const binaryDiv = document.createElement("div");
1616
binaryDiv.style.minHeight = "400px";
1717
const binaryText = document.createElement("div");
@@ -90,7 +90,7 @@ export function start(div: HTMLDivElement, odspAccessToken: string) {
9090
}
9191

9292
// eslint-disable-next-line import-x/no-deprecated
93-
function fetchButtonClick(mockLogger: MockLogger, div: HTMLDivElement) {
93+
function fetchButtonClick(mockLogger: MockLogger, div: HTMLDivElement): void {
9494
const fields = new Set([
9595
"eventName",
9696
"attempts",

examples/benchmarks/odspsnapshotfetch-perftestapp/src/odspPersistantCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class OdspSampleCache implements IPersistedCache {
2020
return this.cache.get(getKeyForCacheEntry(entry));
2121
}
2222

23-
async put(entry: ICacheEntry, value: any) {
23+
async put(entry: ICacheEntry, value: any): Promise<void> {
2424
this.cache.set(getKeyForCacheEntry(entry), value);
2525
}
2626

examples/benchmarks/tablebench/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { Table } from "./tree/index.js";
1010
export { generateTable };
1111
export { Table };
1212

13-
export async function initApp() {
13+
export async function initApp(): Promise<void> {
1414
const { view } = await initFluid();
1515

1616
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17-
document.getElementById("run")!.addEventListener("click", () => {
17+
document.getElementById("run")!.addEventListener("click", (): void => {
1818
performance.mark("start");
1919

2020
for (const row of view.root) {

examples/benchmarks/tablebench/src/azure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const containerSchema = {
3131

3232
const config = new TreeViewConfiguration({ schema: Table });
3333

34-
export async function initFluid() {
34+
export async function initFluid(): Promise<{ view: TreeView<typeof Table> }> {
3535
let container;
3636
let view: TreeView<typeof Table>;
3737

@@ -41,7 +41,7 @@ export async function initFluid() {
4141
view = tree.viewWith(config);
4242
view.initialize(generateTable(10000));
4343
// TODO: Waiting for 'attach()' is a work around for https://dev.azure.com/fluidframework/internal/_workitems/edit/6805
44-
await container.attach().then((containerId) => (location.hash = containerId));
44+
await container.attach().then((containerId: string) => (location.hash = containerId));
4545
} else {
4646
({ container } = await client.getContainer(
4747
location.hash.substring(1),

examples/benchmarks/tablebench/src/data.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import { IRandom, makeRandom } from "@fluid-private/stochastic-test-utils";
7-
import { InsertableTypedNode } from "@fluidframework/tree";
6+
import { type IRandom, makeRandom } from "@fluid-private/stochastic-test-utils";
7+
import type { InsertableTypedNode } from "@fluidframework/tree";
88

99
import { Row } from "./tree/index.js";
1010

@@ -24,7 +24,7 @@ export function generateRow(random: IRandom): InsertableTypedNode<typeof Row> {
2424
["Baby Food", 255.28, 159.42],
2525
]);
2626

27-
const toDollars = (n: number) => Math.round(n * 100) / 100;
27+
const toDollars = (n: number): number => Math.round(n * 100) / 100;
2828

2929
const unitsSold = random.integer(2, 10000);
3030
const totalRevenue = toDollars(unitPrice * unitsSold);
@@ -239,7 +239,7 @@ export function generateRow(random: IRandom): InsertableTypedNode<typeof Row> {
239239
};
240240
}
241241

242-
export function generateTable(rows: number, seed = 1) {
242+
export function generateTable(rows: number, seed = 1): InsertableTypedNode<typeof Row>[] {
243243
const random = makeRandom(seed);
244244

245245
return Array.from({ length: rows }, () => generateRow(random)).sort(

0 commit comments

Comments
 (0)