Add Typescript boilerplate

This commit is contained in:
Matthew Aaron Raymer
2023-08-09 13:51:37 +08:00
parent cffea3e9f8
commit 6b67870d27
9 changed files with 9722 additions and 1 deletions

34
src/main.ts Normal file
View File

@@ -0,0 +1,34 @@
/**
* Some predefined delay values (in milliseconds).
*/
export enum Delays {
Short = 500,
Medium = 2000,
Long = 5000,
}
/**
* Returns a Promise<string> that resolves after a given time.
*
* @param {string} name - A name.
* @param {number=} [delay=Delays.Medium] - A number of milliseconds to delay resolution of the Promise.
* @returns {Promise<string>}
*/
function delayedHello(
name: string,
delay: number = Delays.Medium,
): Promise<string> {
return new Promise((resolve: (value?: string) => void) =>
setTimeout(() => resolve(`Hello, ${name}`), delay),
);
}
// Please see the comment in the .eslintrc.json file about the suppressed rule!
// Below is an example of how to use ESLint errors suppression. You can read more
// at https://eslint.org/docs/latest/user-guide/configuring/rules#disabling-rules
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function greeter(name: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
// The name parameter should be of type string. Any is used only to trigger the rule.
return await delayedHello(name, Delays.Long);
}