Add Typescript boilerplate
This commit is contained in:
34
src/main.ts
Normal file
34
src/main.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user