Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
7386009
Start refactor page
chibicode Dec 23, 2019
be70d31
Start writing refactor article
chibicode Dec 24, 2019
d4f8634
Add emojis
chibicode Dec 25, 2019
9aaef52
Wordsmith
chibicode Dec 25, 2019
d167657
Finish intro
chibicode Dec 25, 2019
efd3fa0
Start tip 1
chibicode Dec 25, 2019
e79218d
Wordsmith
chibicode Dec 25, 2019
bb1752f
Wordsmith
chibicode Dec 25, 2019
009df3b
Slide 2 start
chibicode Dec 25, 2019
01fb099
Refactor
chibicode Dec 25, 2019
7c0da50
Continue w/ slide 2
chibicode Dec 25, 2019
4a2b77c
Wordsmith
chibicode Dec 25, 2019
c7fe3a2
Wordsmith
chibicode Dec 26, 2019
20dbc63
Wordsmith
chibicode Dec 26, 2019
aa0f5b0
Simplify
chibicode Dec 26, 2019
7a8b645
Slide 2
chibicode Dec 27, 2019
d0df08c
Finish tip 1
chibicode Dec 27, 2019
8509b47
Rewrite 1
chibicode Dec 27, 2019
95c5c6e
Improve slide 2
chibicode Dec 27, 2019
1423c54
Start slide 3
chibicode Dec 27, 2019
006e409
Remove run button text and simplify
chibicode Dec 27, 2019
06ac546
Rewrite 1 again
chibicode Dec 28, 2019
8304366
Simplify the conclusion
chibicode Dec 28, 2019
1e6b1d0
Simplify slide 2
chibicode Dec 28, 2019
e95459c
Add prettier
chibicode Dec 28, 2019
faccf23
Finish slide 2
chibicode Dec 28, 2019
9d37628
Simplify slide 1
chibicode Dec 28, 2019
d611b27
Wordsmith
chibicode Dec 28, 2019
721052b
Change slide 3
chibicode Dec 28, 2019
b952dc2
Fix cursor: pointer
chibicode Dec 28, 2019
905ae2c
Keep text decoration on read more
chibicode Dec 28, 2019
79c81e5
Wordsmith
chibicode Dec 29, 2019
f7730b4
ScaryCat
chibicode Dec 29, 2019
e450109
Wordsmith
chibicode Dec 29, 2019
3c72d05
Finish slide 3
chibicode Dec 29, 2019
e28d30f
Wordsmith, left align emojiSeparator
chibicode Dec 29, 2019
7f618c8
Wordsmith
chibicode Dec 29, 2019
12e569a
Wordsmith, add remaining titles
chibicode Dec 29, 2019
13bc538
Make emojis clickable
chibicode Dec 29, 2019
59ad286
Add remaining cards
chibicode Dec 29, 2019
df24f4c
Wordsmith
chibicode Dec 29, 2019
2e6f7c2
Wordsmith
chibicode Dec 29, 2019
40a1597
Wordsmith
chibicode Dec 29, 2019
f5aa813
Extra credit
chibicode Dec 29, 2019
ce2be0c
Revert "Extra credit"
chibicode Dec 29, 2019
e271859
Add all emojis
chibicode Dec 29, 2019
a6a2ea4
Update bad example icon
chibicode Dec 30, 2019
24acec1
Start slide 3
chibicode Dec 30, 2019
9d5bda9
Update description
chibicode Dec 30, 2019
6e691a0
Wordsmith
chibicode Dec 30, 2019
5c46cb3
Simplify
chibicode Dec 30, 2019
ea14e88
Add official website doc
chibicode Dec 30, 2019
84f9f22
Start slide 3
chibicode Dec 30, 2019
b6aba69
Test slide 3
chibicode Dec 30, 2019
e9af436
Continue with slide 3
chibicode Dec 30, 2019
0d55011
Wordsmith
chibicode Dec 30, 2019
dd8e912
Wordsmith
chibicode Dec 31, 2019
4a6eb8a
Add comment
chibicode Dec 31, 2019
c75a45b
Adjust spacing
chibicode Dec 31, 2019
7ff649d
Finish slide 3
chibicode Dec 31, 2019
a1c44c2
Add rocket
chibicode Dec 31, 2019
2d88500
Update og image
chibicode Dec 31, 2019
f59e73d
Highlight refactor
chibicode Dec 31, 2019
0c23b0d
Highlight text
chibicode Dec 31, 2019
3d50140
Continue with tip 3
chibicode Dec 31, 2019
4c3a6f5
Continue with tip 3
chibicode Dec 31, 2019
623d8f7
Continue with tip 3
chibicode Dec 31, 2019
660712b
Wordsmith
chibicode Dec 31, 2019
d2aa4ae
Add total number of tips
chibicode Dec 31, 2019
8953652
Remove part 7
chibicode Dec 31, 2019
4d11c04
Finish tip 3
chibicode Dec 31, 2019
b22a7d8
Enhance paddingLeftCss
chibicode Dec 31, 2019
cc40ce7
Add monkeys
chibicode Dec 31, 2019
e45c5e2
Revert "Add monkeys"
chibicode Dec 31, 2019
6e116e5
Start slide 6
chibicode Dec 31, 2019
789815c
Finish tip 5
chibicode Dec 31, 2019
2b9203f
White70
chibicode Dec 31, 2019
ee652b6
Wordsmith
chibicode Dec 31, 2019
11c5561
Wordsmith
chibicode Dec 31, 2019
a072911
Wordsmith
chibicode Dec 31, 2019
5a878b1
Continue with tip 6
chibicode Dec 31, 2019
5e0eb3f
Continue with slide 7
chibicode Jan 1, 2020
2c15525
Finish tip 6
chibicode Jan 1, 2020
4c7b3ee
Done with first draft
chibicode Jan 1, 2020
1a366be
Add hr
chibicode Jan 1, 2020
a23c1f5
Add a note about translation
chibicode Jan 1, 2020
601494f
Update README.md
chibicode Jan 1, 2020
a79187c
Wordsmith
chibicode Jan 1, 2020
dafb7ca
Finish tip 4
chibicode Jan 1, 2020
d999c5e
Add blockquote
chibicode Jan 1, 2020
4a8b176
Move ...
chibicode Jan 1, 2020
af778e8
Wordsmith conclusion
chibicode Jan 1, 2020
8809626
Wordsmith tip 6
chibicode Jan 1, 2020
133880a
Wordsmith tip 3
chibicode Jan 1, 2020
b9843de
Finish wordsmith
chibicode Jan 1, 2020
4c64d71
Adjust spacing
chibicode Jan 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"options": {
"printWidth": 53
}
},
{
"files": ["snippets/snippets/**/ignoreWidth/*.ts"],
"options": {
"printWidth": 120
}
}
]
}
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# [TypeScript for Beginner Programmers](https://ts.chibicode.com)

### This is the repository for the TypeScript tutorial website called **[TypeScript for Beginner Programmers](https://ycombinator.chibicode.com/)**.
This is the repository for the TypeScript tutorial website called **[TypeScript for Beginner Programmers](https://ycombinator.chibicode.com/)**.

<p>
<a href="https://ts.chibicode.com/"><img src="public/images/og-index.png" width="600" /></a>
</p>

## Article 3: [Your Coding Tutorial Might Need Some Refactoring](https://ts.chibicode.com/refactor)

<p>
<a href="https://ts.chibicode.com/refactor"><img src="public/images/og-refactor.png" width="600" /></a>
</p>

## Article 2: [TypeScript Tutorial for JS Programmers Who Know How to Build a Todo App](https://ts.chibicode.com/todo)

<p>
<a href="https://ts.chibicode.com/todo"><img src="public/images/og-todo-v2.png" width="600" /></a>
</p>

## Article 1: [TypeScript Generics for People Who Gave Up on Understanding Generics](https://ts.chibicode.com/generics)

<p>
<a href="https://ts.chibicode.com/generics"><img src="public/images/og-generics.png" width="600" /></a>
</p>

## License & Credits

- For emojis, I’m using [Twemoji](https://github.com/twitter/twemoji) by Twitter (CC-BY 4.0 license).
Expand All @@ -16,6 +34,6 @@

**Shu Uesugi**

- Twitter: [@chibicode](https://twitter.com/chibicode)
- [Website](https://chibicode.com)
- Twitter: [@chibicode](https://twitter.com/chibicode)
- Email: [shu@chibicode.com](mailto:shu@chibicode.com)
Binary file added public/images/og-refactor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/refactor/asOfWriting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/refactor/tsdoc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 16 additions & 5 deletions snippets/bin/generateSnippetsBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@ const glob = require('glob')
const fs = require('fs')
const chokidar = require('chokidar')

const filePathToKey = (file: string) =>
file
.replace(/\.\/snippets\/snippets\/\w+\//, '')
.replace(/longerWidth\//, '')
.replace(/ignoreWidth\//, '')
.replace(/\.ts/, '')

const regenerate = () => {
glob('./snippets/snippets/**/*.ts', (_: any, files: readonly string[]) => {
if (
new Set(files.map(filePathToKey)).size !== files.map(filePathToKey).length
) {
throw new Error('Duplicate file name')
}

const result = files
.map(file => {
const contents = fs.readFileSync(file, 'utf8')
return `export const ${file
.replace(/\.\/snippets\/snippets\/\w+\//, '')
.replace(/longerWidth\//, '')
.replace(/\.ts/, '')} = \`${contents
return `export const ${filePathToKey(file)} = \`${contents
.trim()
.replace(/^;/m, '')
.replace(/`/g, '\\`')}\``
.replace(/`/g, '\\`')
.replace(/\$/g, '\\$')}\``
})
.join('\n\n')

Expand Down
5 changes: 5 additions & 0 deletions snippets/snippets/refactor/bxzx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// It could have been useful if you could pass
// both number AND string, and have it repeat
// the string the specified number of times
padLeft('Hello world', 4, '#')
// → "####Hello world"
6 changes: 6 additions & 0 deletions snippets/snippets/refactor/crgn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// If the second parameter is string, then
// that string is appended to the left side
padLeft('Hello world', 'Jim: ')
// → "Jim: Hello world"

// Ask yourself: Would you EVER do this?
16 changes: 16 additions & 0 deletions snippets/snippets/refactor/hfdq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function paddingLeftCss(val: number | string) {
if (typeof val === 'number') {
return `padding-left: ${val * 0.25}rem;`
} else {
return `padding-left: ${val};`
}
}

// padding-left: 0.25rem;
paddingLeftCss(1)

// padding-left: 0.5rem;
paddingLeftCss(2)

// padding-left: 10%;
paddingLeftCss('10%')
1 change: 1 addition & 0 deletions snippets/snippets/refactor/ignoreWidth/mvsz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function makePair<F extends number | string, S extends boolean | F>() {}
1 change: 1 addition & 0 deletions snippets/snippets/refactor/ignoreWidth/zgvn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Todo = Readonly<{ id: number; text: string; done: boolean; place: Place }>
9 changes: 9 additions & 0 deletions snippets/snippets/refactor/lcfe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// If the second parameter is number, then that
// number of spaces is added to the left side
padLeft('Hello world', 4)
// → " Hello world"

// If the second parameter is string, then
// that string is appended to the left side
padLeft('Hello world', 'Jim: ')
// → "Jim: Hello world"
19 changes: 19 additions & 0 deletions snippets/snippets/refactor/longerWidth/riis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Takes a string and adds "padding" to the left.
*
* If 'padding' is a number, then that number of
* spaces is added to the left side.
*
* If 'padding' is a string, then 'padding' is
* appended to the left side.
*/
function padLeft(
value: string,
padding: number | string
) {
if (typeof padding === 'number') {
return Array(padding + 1).join(' ') + value
} else {
return padding + value
}
}
1 change: 1 addition & 0 deletions snippets/snippets/refactor/lplh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(1 + 2)
37 changes: 37 additions & 0 deletions snippets/snippets/refactor/onux.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function extend<First, Second>(
first: First,
second: Second
): First & Second {
const result: Partial<First & Second> = {}
for (const prop in first) {
if (first.hasOwnProperty(prop)) {
;(result as First)[prop] = first[prop]
}
}
for (const prop in second) {
if (second.hasOwnProperty(prop)) {
;(result as Second)[prop] = second[prop]
}
}
return result as First & Second
}

class Person {
constructor(public name: string) {}
}

interface Loggable {
log(name: string): void
}

class ConsoleLogger implements Loggable {
log(name) {
console.log(`Hello, I'm ${name}.`)
}
}

const jim = extend(
new Person('Jim'),
ConsoleLogger.prototype
)
jim.log(jim.name)
13 changes: 13 additions & 0 deletions snippets/snippets/refactor/vnfq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type Person = { name: string }
type Loggable = { log: (name: string) => void }

// Use & to make jim BOTH Person AND Loggable
const jim: Person & Loggable = {
name: 'Jim',
log: name => {
console.log(`Hello, I'm ${name}.`)
}
}

// "Hello, I’m Jim."
jim.log(jim.name)
4 changes: 4 additions & 0 deletions snippets/snippets/refactor/xwbz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function makePair<
F extends number | string,
S extends boolean | F
>() {}
32 changes: 17 additions & 15 deletions src/components/BubbleQuotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import useTheme from 'src/hooks/useTheme'
import { allColors } from 'src/lib/theme/colors'

interface BubbleQuoteProps {
type: keyof typeof emojiToComponent
type?: keyof typeof emojiToComponent
children: React.ReactNode
backgroundColor?: keyof typeof allColors
}
Expand Down Expand Up @@ -39,21 +39,23 @@ const BubbleQuotes = ({
display: flex;
`}
>
<div
css={css`
font-size: ${size === 'lg' ? fontSizes(2) : fontSizes(1.6)};
margin-right: ${size === 'lg' ? spaces(0.5) : spaces(0.25)};
padding-top: ${spaces(0.5)};
{type && (
<div
css={css`
font-size: ${size === 'lg' ? fontSizes(2) : fontSizes(1.6)};
margin-right: ${size === 'lg' ? spaces(0.5) : spaces(0.25)};
padding-top: ${spaces(0.5)};

${ns} {
padding-top: ${size === 'lg' ? spaces(0) : spaces(0.25)};
margin-right: ${size === 'lg' ? spaces(1) : spaces(0.75)};
font-size: ${size === 'lg' ? fontSizes(4) : fontSizes(2)};
}
`}
>
<Emoji type={type} />
</div>
${ns} {
padding-top: ${size === 'lg' ? spaces(0) : spaces(0.25)};
margin-right: ${size === 'lg' ? spaces(1) : spaces(0.75)};
font-size: ${size === 'lg' ? fontSizes(4) : fontSizes(2)};
}
`}
>
<Emoji type={type} />
</div>
)}
<div
css={css`
background: ${colors(backgroundColor)};
Expand Down
64 changes: 45 additions & 19 deletions src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export interface CardProps {
color?: 'default' | 'pink' | 'green' | 'darkGreen'
slideNumber?: number
slideCount?: number
isLast?: boolean
isFirst?: boolean
title?: React.ReactNode
heading?: React.ReactNode
subtitle?: React.ReactNode
anchor?: string
footer?: {
content: React.ReactNode
color?: CardProps['color']
Expand All @@ -42,19 +43,39 @@ const Card = ({
children,
slideNumber,
slideCount,
isLast,
isFirst,
footer,
heading,
subtitle
subtitle,
anchor
}: CardProps) => {
const { ns, colors, fontSizes, spaces, radii, lineHeights } = useTheme()
const {
ns,
colors,
fontSizes,
spaces,
radii,
lineHeights,
letterSpacings
} = useTheme()
return (
<>
{!isFirst && (
<div
id={anchor}
css={css`
width: 1.25rem;
height: 2rem;
margin: 0 auto;
background: ${colors('paleGreen')};
`}
/>
)}
<div
css={css`
position: relative;
margin-left: ${spaces('-0.75')};
margin-right: ${spaces('-0.75')};
margin-left: -0.6rem;
margin-right: -0.6rem;

${ns} {
margin-left: ${spaces('-1.5')};
Expand All @@ -80,7 +101,7 @@ const Card = ({
<>
<span
css={css`
color: ${colors('white85')};
color: ${colors('white70')};
`}
>
Slide{' '}
Expand All @@ -94,7 +115,7 @@ const Card = ({
</span>{' '}
<span
css={css`
color: ${colors('white85')};
color: ${colors('white70')};
font-weight: bold;
`}
>
Expand Down Expand Up @@ -189,7 +210,7 @@ const Card = ({
padding: ${spaces(0.75)};

${ns} {
padding-top: ${spaces(1.25)};
padding-top: ${spaces(1)};
padding-left: ${spaces(1.5)};
padding-right: ${spaces(1.5)};
padding-bottom: ${spaces(1)};
Expand All @@ -199,21 +220,26 @@ const Card = ({
border-bottom-left-radius: ${radii(0.5)};
`}
>
<h4
css={css`
text-align: center;

margin: ${spaces(0.25)} 0 ${spaces(0.75)};
line-height: ${lineHeights(0.85)};
font-size: ${fontSizes(0.85)};

letter-spacing: ${letterSpacings('wide')};
text-transform: uppercase;
color: ${colors('brown')};
`}
>
Side Note
</h4>
{footer.content}
</div>
)}
</div>
</div>
{!isLast && (
<div
css={css`
width: 1.25rem;
height: 2rem;
margin: 0 auto;
background: ${colors('paleGreen')};
`}
/>
)}
</>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CardTitleText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { css, jsx } from '@emotion/core'
import useTheme from 'src/hooks/useTheme'

const CardTitleText = (props: JSX.IntrinsicElements['h3']) => {
const { fontSizes, lineHeights, ns, spaces } = useTheme()
const { fontSizes, lineHeights, ns, spaces, letterSpacings } = useTheme()
return (
<h3
css={css`
margin: 0 0 ${spaces(1, true)};
font-size: ${fontSizes(1.2)};
line-height: ${lineHeights(1.2)};

letter-spacing: ${letterSpacings('titleSmall')};
${ns} {
line-height: ${lineHeights(1.4)};
font-size: ${fontSizes(1.4)};
Expand Down
Loading