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
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
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
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
interface User { | |
name: string; | |
} | |
interface HappyUser extends User { | |
clap: () => void; | |
} | |
function printName<T extends User>(someone: T): T { | |
console.log(someone.name); |
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 HttpResponse<T> { | |
code: number; | |
data: T; | |
} | |
interface ResponseData { | |
completed: boolean; | |
id: number; | |
title: string; | |
userId: number; |
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 rollDice(array: any[]): number { | |
return Math.floor(Math.random() * array.length); | |
} | |
function getRandoms<A, B>(as: A[], bs: B[]): [A, B] { | |
const a = as[rollDice(as)]; | |
const b = bs[rollDice(bs)]; | |
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
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' | |
]; |
NewerOlder