Skip to content

Commit 5726656

Browse files
committed
Archive notes
1 parent 527f6fe commit 5726656

6 files changed

+46
-46
lines changed

_layouts/post.liquid

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ layout: base
2525
</h2>
2626
{% endif %}
2727
</h1>
28+
{% if note %}
29+
<p class="font-grotesk rounded-lg bg-[var(--color-fg05)] p-2">
30+
{{ note }}
31+
</p>
32+
{% endif %}
2833
{% if not bigTitle %}
2934
<p>
3035
<time class="font-grotesk font-medium text-textMuted" datetime="{{ date | htmlDateString }}">

content/posts/archive/2019-01-19_Expressive-React-Component-APIs-with-Discriminated-Unions.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@ date: 2019-02-06
44
permalink: expressive-react-component-apis-with-discriminated-unions/
55
tags: archive
66
layout: post
7-
globalPreamble: "declare var onChange: () => void;declare var console: { log: Function };\n"
8-
preambles:
9-
- file: select-1.tsx
10-
text: "import React from 'react';\n"
11-
- file: select-2.tsx
12-
text: "import React from 'react';\n"
13-
- file: select-3.tsx
14-
text: "import React from 'react';\n"
15-
lib:
16-
- react
17-
note: '
18-
When I wrote this piece, I realized it would be much easier to explain if I could show you how the TypeScript compiler handles the code I’m talking about, as if we were both sitting in front of your favorite code editor with language support. So, I built this blog to imitate that experience. Hover (or tap) on code underlined in red to see errors, hover identifiers to see type information, and even edit the samples if you want. I also <a href="/overengineering-a-blog-prologue-an-ode-to-red-squigglies/">wrote more</a> about why I did this.
19-
20-
21-
Disclaimer: I wrote this before joining the TypeScript team. I’m not speaking officially for TypeScript or Microsoft in
22-
any post on this blog, but I’m especially not in this one.'
7+
note: |
8+
This post has been archived and delisted. The code examples relied on my
9+
<a href="/overengineering-a-blog">previous blog infrastructure</a>, which showed
10+
live TypeScript errors and type information. Ultimately, that was not worth the
11+
upkeep and has been removed. Consequently, this post may not make sense without
12+
seeing the errors that are supposed to be rendered. The content also refers to
13+
very old versions of TypeScript, React, and <code>@types/react</code> and may
14+
no longer be accurate.
2315
---
2416

2517
One of TypeScript’s most underrated features is _discriminated union types_. Borrowed primarily from functional programming (FP) languages, they match an elegant FP concept to a pattern people intuitively write in JavaScript. Discriminated unions also enable a useful pattern for typing complex React component props more safely and expressively. But first, we’ll review what discriminated unions look like independent of React.

content/posts/archive/2019-02-06_Overengineering_A_Blog_Prologue.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
---
22
title: Overengineering a Blog, Prologue
33
subtitle: An Ode to Red Squigglies
4-
permalink: overengineering-a-blog-prologue-an-ode-to-red-squigglies/
4+
permalink: overengineering-a-blog-prologue/
55
date: 2019-02-07
66
tags: archive
77
layout: post
8+
note: |
9+
This post describes the infrastructure of this blog before a more recent rewrite,
10+
where I removed all the cool features described herein. The blog is now made with
11+
<a href="https://11ty.dev">eleventy</a> and doesn’t have interactive code blocks.
12+
Ultimately, it wasn’t worth the upkeep.
813
---
914

1015
<span class="small-caps">It’s all about the red squigglies.</span> Red squigglies in Microsoft products have been saving me from looking stupid since the second grade, and now they save me from writing stupid code on a minutely basis. Well, significantly less stupid code. You know the red squigglies I’m talking about? The red squigglies that tell you that no, it’s not spelled “bureauacracy,” and, more frequently for me lately, that object is possibly `undefined`.

content/posts/archive/2019-02-16_Overengineering_A_Blog.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ date: 2019-02-16
44
tags: archive
55
permalink: overengineering-a-blog/
66
layout: post
7-
note: 'Disclaimer: I wrote this before joining the TypeScript team. I’m not speaking officially for TypeScript or Microsoft in any post on this blog, but I’m especially not in this one.'
7+
note: |
8+
This post describes the infrastructure of this blog before a more recent rewrite,
9+
where I removed all the cool features described herein. The blog is now made with
10+
<a href="https://11ty.dev">eleventy</a> and doesn’t have interactive code blocks.
11+
Ultimately, it wasn’t worth the upkeep.
812
lib:
913
- react
1014
preambles:
@@ -135,7 +139,11 @@ I’m telling this piece of the story a little out of order, because I think it
135139

136140
<figure>
137141
{% image "./images/bundle-analysis.png", "A graphical representation of the blog’s assets by size, as provided by webpack-bundle-analyzer. TypeScript takes up the entire left half of the chart, plus some." %}
138-
<figcaption>[webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) shows TypeScript’s size relative to everything else.</figcaption>
142+
<figcaption>
143+
144+
[webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) shows TypeScript’s size relative to everything else.
145+
146+
</figcaption>
139147
</figure>
140148

141149
I also realized that none of the really heavy pieces are necessary until the moment a reader starts _editing_ a code sample. I could analyze the initial code at build time, generate syntax highlighting information, type information, and compiler diagnostics as static data, inject it with GraphQL, and reference it during render, all for a fraction of the weight of the compiler and syntax highlighter itself.

content/posts/archive/2019-08-05_Writing_Type_Safe_Polymorphic_React_Components_(Without_Crashing_TypeScript).md

+8-27
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,14 @@ permalink: polymorphic-react-components/
55
tags: archive
66
layout: post
77
metaImage: images/rabbit-bg.png
8-
globalPreamble: "
9-
import * as React from 'react';
10-
interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> { to: string }
11-
declare function Link(props: LinkProps): JSX.Element;
12-
declare function Icon(props: any): JSX.Element;
13-
declare function FlexContainer(props: any): JSX.Element;
14-
declare function getClassName(color: ColorName | undefined, ...others: (string | undefined)[]): string;
15-
declare enum ColorName { Blue = 'blue' };
16-
declare enum IconName {};
17-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;\n
18-
"
19-
preambles:
20-
- file: GoodButton.tsx
21-
text: "
22-
declare function mergeProps<T extends {}[]>(...props: T): {
23-
[K in keyof UnionToIntersection<T[number]>]:
24-
K extends 'className' ? string :
25-
K extends 'style' ? UnionToIntersection<T[number]>[K] :
26-
Extract<T[number], { [Q in K]: unknown; }>[K]; }\n
27-
"
28-
lib:
29-
- react
30-
- dom
31-
compilerOptions:
32-
lib:
33-
- /lib.es2015.d.ts
34-
- /lib.dom.d.ts
8+
note: |
9+
This post has been archived and delisted. The code examples relied on my
10+
<a href="/overengineering-a-blog">previous blog infrastructure</a>, which showed
11+
live TypeScript errors and type information. Ultimately, that was not worth the
12+
upkeep and has been removed. Consequently, this post may not make sense without
13+
seeing the errors that are supposed to be rendered. The content also refers to
14+
very old versions of TypeScript, React, and <code>@types/react</code> and may
15+
no longer be accurate.
3516
---
3617

3718
<span class="small-caps">When designing a React component for reusability</span>, you often need to be able to pass different DOM attributes to the component’s container in different situations. Let’s say you’re building a `<Button />`. At first, you just need to allow a custom `className` to be merged in, but later, you need to support a wide range of attributes and event handlers that aren’t related to the component itself, but rather the context in which it’s used—say, `aria-describedby` when composed with a Tooltip component, or `tabIndex` and `onKeyDown` when contained in a component that manages focus with arrow keys.

content/styles/main.css

+9
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ pre {
258258
margin-bottom: calc(var(--rhythm) * 0.5rem);
259259
}
260260

261+
picture {
262+
display: block;
263+
text-align: center;
264+
}
265+
266+
picture img {
267+
display: inline-block;
268+
}
269+
261270
figure img {
262271
margin-bottom: 0;
263272
}

0 commit comments

Comments
 (0)