Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
Working from home

Benny Neugebauer bennycode

🏡
Working from home
View GitHub Profile
@bennycode
bennycode / webpack.config.js
Created Aug 15, 2022
Multiple Webpack Output Libraries
View webpack.config.js
module.exports = {
devtool: 'source-map',
entry: {
[projectName]: `${__dirname}/${pkg.main}`,
},
externals: {
dexie: 'Dexie',
},
mode: 'production',
output: {
@bennycode
bennycode / never.ts
Last active Aug 14, 2022
Never Type
View never.ts
interface StreamResponse {
status: StreamStatus;
}
enum StreamStatus {
IDLE,
ONLINE,
OFFLINE,
}
View Type-Guard.ts
type Dog = {
age: number;
name: string;
bark: () => void;
type: 'dog'
}
type Person = {
age: number;
name: string;
@bennycode
bennycode / generic-inheritance.ts
Created May 15, 2022
Generic Types and Inheritance in TypeScript
View generic-inheritance.ts
interface User {
name: string;
}
interface HappyUser extends User {
clap: () => void;
}
function printName<T extends User>(someone: T): T {
console.log(someone.name);
@bennycode
bennycode / generic-interface.ts
Created May 15, 2022
Generic interfaces in TypeScript
View generic-interface.ts
interface HttpResponse<T> {
code: number;
data: T;
}
interface ResponseData {
completed: boolean;
id: number;
title: string;
userId: number;
@bennycode
bennycode / multiple-generic-types.ts
Created May 15, 2022
Multiple generic types in TypeScript
View multiple-generic-types.ts
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];
}
@bennycode
bennycode / generic-function.ts
Last active May 15, 2022
Generic Functions in TypeScript
View generic-function.ts
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'
];
@bennycode
bennycode / generic-class.ts
Last active May 16, 2022
Generic Classes in TypeScript
View generic-class.ts
class KeyValuePair<KeyType, ValueType> {
key: KeyType;
value: ValueType;
constructor(key: KeyType, value: ValueType) {
this.key = key;
this.value = value;
}
}
View functionOverload.ts
function sum(a: number, b: number): number;
function sum(a: string, b: string): string;
function sum(a: number | string, b: number | string): number | string {
if (typeof a === "number" && typeof b === "number") {
return a + b;
} else {
return `${parseInt(`${a}`, 10) + parseInt(`${b}`, 10)}`;
}
}
View youtube-urls.txt
Playlist: https://www.youtube.com/playlist?list=PLCbdBdyNHZXLX9p_F8WCPwXHn67QlstZ9
Video in Playlist: https://www.youtube.com/watch?v=qZN0Lo-f3iE&list=PLCbdBdyNHZXLX9p_F8WCPwXHn67QlstZ9
Video: https://www.youtube.com/watch?v=qZN0Lo-f3iE