Skip to content

Instantly share code, notes, and snippets.

View mscolnick's full-sized avatar

Myles Scolnick mscolnick

View GitHub Profile
interface Person {
name: string;
age: number;
location: string;
}
type P1 = Person["name"]; // string
type P2 = string[][0]; // string
type P3 = string[]["length"]; // number
type P4 = [string]["length"]; // 1
function fibonacci(num) {
if (num <= 1) {
return 1;
}
return fibonacci(num - 1) + fibonacci(num - 2);
}
@mscolnick
mscolnick / arithmetic.ts
Created March 15, 2021 03:55
The Fibonacci sequence in TypeScript
type Plus1<A extends any[]> = [true, ...A];
type Add<A extends any[], B extends any[]> = [...A, ...B];
type Minus1<A extends any[]> = A extends readonly [any?, ...infer U] ? U : [...A];
type Minus2<A extends any[]> = Minus1<Minus1<A>>;
// verify
type D = Plus1<A>; // [true, true, true, true]
type E = Minus1<A>; // [true, true]
type F = Minus2<A>; // [true]
@mscolnick
mscolnick / example.ts
Created November 20, 2020 16:19
styled-utils
const SectionedListWrapper = styled.div<{ clickable?: boolean; bordered?: boolean }>`
display: flex;
flex-direction: column;
${padding.b('$8')}
${cond.if(
'clickable',
css`
> *:not(:first-child):hover {
cursor: pointer;