This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function emitExit(signal: string) { | |
const exitCode = 0; | |
console.log(`Received "${signal}" signal. Will terminate with exit code "${exitCode}".`); | |
process.exit(exitCode); | |
} | |
// Catches Ctrl + C events | |
process.on('SIGINT', () => emitExit('SIGINT')); | |
// Catches "kill pid" events (for example: nodemon restarts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
// Code | |
"rootDir": "src", // ⟵ In | |
"outDir": "dist", // ⟵ Out | |
// Syntax | |
"lib": ["ES2022"], // ← In | |
"target": "ES2022", // ← Out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasErrorCode = (error: unknown): error is { code: string } => { | |
return !!error && typeof error === 'object' && 'code' in error && typeof error.code === 'string'; | |
}; | |
try { | |
throw {code: 72}; | |
} catch (error: unknown) { | |
if (hasErrorCode(error)) { | |
console.error(`Failed with error code "${error.code}".`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(a, b) { | |
return a + b; | |
} | |
exports.add = add; | |
function substract(a, b) { | |
return a - b; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
devtool: 'source-map', | |
entry: { | |
[projectName]: `${__dirname}/${pkg.main}`, | |
}, | |
externals: { | |
dexie: 'Dexie', | |
}, | |
mode: 'production', | |
output: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface StreamResponse { | |
status: StreamStatus; | |
} | |
enum StreamStatus { | |
IDLE, | |
ONLINE, | |
OFFLINE, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Dog = { | |
age: number; | |
name: string; | |
bark: () => void; | |
type: 'dog' | |
} | |
type Person = { | |
age: number; | |
name: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KeyValuePair<KeyType, ValueType> { | |
key: KeyType; | |
value: ValueType; | |
constructor(key: KeyType, value: ValueType) { | |
this.key = key; | |
this.value = value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRandom<T>(array: T[]): T { | |
const diceRoll = Math.floor(Math.random() * array.length); | |
return array[diceRoll]; | |
} | |
const names = [ | |
'Amelia', 'Ava', 'Benjamin', 'Charlotte', 'Elijah', 'Emma', | |
'Evelyn', 'Harper', 'Henry', 'Isabella', 'James', 'Liam', 'Lucas', 'Mia', | |
'Noah', 'Oliver', 'Olivia', 'Sofia', 'Theodore', 'William' | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface User { | |
name: string; | |
} | |
interface HappyUser extends User { | |
clap: () => void; | |
} | |
function printName<T extends User>(someone: T): T { | |
console.log(someone.name); |
NewerOlder