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
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
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"files": "snippets/snippets/**/*.ts",
"options": {
"printWidth": 49
"printWidth": 48
}
}
]
Expand Down
13 changes: 13 additions & 0 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://ts.chibicode.com</loc>
</url>
<url>
<loc>https://ts.chibicode.com/generics</loc>
</url>
</urlset>
6 changes: 3 additions & 3 deletions snippets/snippets/generics/bfka.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// We want to modify createState() to support
// We want to modify makeState() to support
// creating two different states:

// One that only allows numbers, and…
const numState = createState()
const numState = makeState()
numState.setState(1)
console.log(numState.getState()) // 1

// The other that only allows strings.
const strState = createState()
const strState = makeState()
strState.setState('foo')
console.log(strState.getState()) // foo
2 changes: 1 addition & 1 deletion snippets/snippets/generics/brze.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState<S>() {
function makeState<S>() {
let state: S

function getState() {
Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/cbeq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getState, setState } = createState()
const { getState, setState } = makeState()

setState(1)
console.log(getState())
Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/cupt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState() {
function makeState() {
let state: number

function getState() {
Expand Down
6 changes: 3 additions & 3 deletions snippets/snippets/generics/defo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState<S>() {
function makeState<S>() {
let state: S

function getState() {
Expand All @@ -12,10 +12,10 @@ function createState<S>() {
return { getState, setState }
}

const numState = createState<number>()
const numState = makeState<number>()
numState.setState(1)
console.log(numState.getState())

const strState = createState<string>()
const strState = makeState<string>()
strState.setState('foo')
console.log(strState.getState())
18 changes: 18 additions & 0 deletions snippets/snippets/generics/dngl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function makeState<
S extends number | string
>() {
let state: S

function getState() {
return state
}

function setState(x: S) {
state = x
}

return { getState, setState }
}

// What happens if we now pass boolean to S?
const boolState = makeState<boolean>()
2 changes: 1 addition & 1 deletion snippets/snippets/generics/gjgg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Creates a number-only state
const numState = createState<number>()
const numState = makeState<number>()
numState.setState(1)
console.log(numState.getState())

Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/gkgi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState() {
function makeState() {
// Change to string
let state: string

Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/hkgv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Creates a string-only state
const strState = createState<string>()
const strState = makeState<string>()
strState.setState('foo')
console.log(strState.getState())

Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/jdhu.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// It sets S as number
createState<number>()
makeState<number>()
4 changes: 4 additions & 0 deletions snippets/snippets/generics/llvc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Creates a boolean-only state
const boolState = makeState<boolean>()
boolState.setState(true)
console.log(boolState.getState())
1 change: 1 addition & 0 deletions snippets/snippets/generics/mngc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function makeState<S extends number | string>()
2 changes: 1 addition & 1 deletion snippets/snippets/generics/nnyl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState() {
function makeState() {
let state: number

function getState() {
Expand Down
4 changes: 2 additions & 2 deletions snippets/snippets/generics/osaa.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState() {
function makeState() {
// Change to string
let state: string

Expand All @@ -14,7 +14,7 @@ function createState() {
return { getState, setState }
}

const { getState, setState } = createState()
const { getState, setState } = makeState()

setState('foo')
console.log(getState())
2 changes: 1 addition & 1 deletion snippets/snippets/generics/qqic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Doesn't work because the created state…
const numAndStrState = createState()
const numAndStrState = makeState()

// Supports both numbers…
numAndStrState.setState(1)
Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/rebo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// In the function definition of createState()
// In the function definition of makeState()
let state: S // <- number

function setState(x: S /* <- number */) {
Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/stkh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getState, setState } = createState()
const { getState, setState } = makeState()

// What happens if we use a string instead?
setState('foo')
Expand Down
4 changes: 2 additions & 2 deletions snippets/snippets/generics/udpv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState() {
function makeState() {
let state: number

function getState() {
Expand All @@ -12,7 +12,7 @@ function createState() {
return { getState, setState }
}

const { getState, setState } = createState()
const { getState, setState } = makeState()

setState(1)
console.log(getState())
Expand Down
2 changes: 1 addition & 1 deletion snippets/snippets/generics/xeax.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getState, setState } = createState()
const { getState, setState } = makeState()

setState('foo')
console.log(getState())
2 changes: 1 addition & 1 deletion snippets/snippets/generics/ystu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState() {
function makeState() {
let state: number | string

function getState() {
Expand Down
4 changes: 2 additions & 2 deletions snippets/snippets/generics/zhql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createState() {
function makeState() {
let state: number

function getState() {
Expand All @@ -12,7 +12,7 @@ function createState() {
return { getState, setState }
}

const { getState, setState } = createState()
const { getState, setState } = makeState()

setState('foo')
console.log(getState())
26 changes: 26 additions & 0 deletions src/components/Emoji/ChickEgg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'

const SvgChickEgg = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 36 36" {...props}>
<path
fill="#99AAB5"
d="M2.75 19.333L5 16l3 3 4-2 3 3 4-6 4 3 3-1 2 3 3-3 2 4-2 7-11 5-11-2-6-6z"
/>
<path
fill="#FFCC4D"
d="M29.956 14.712c.021-.287.044-.574.044-.866 0-5.943-4.324-10.864-9.996-11.819 1.189-.26 2.031-.509.996-1.027-1.115-.558-2.23.129-2.999.846h-.002C17.23 1.129 16.116.442 15 1c-1.035.518-.193.767.996 1.026C10.325 2.981 6 7.902 6 13.846c0 .292.023.579.044.867C5.562 21.313-.259 31 18 31s12.438-9.687 11.956-16.288z"
/>
<path
fill="#F4900C"
d="M21 14c0 1.657-1.343 2-3 2s-3-.343-3-2 1.343-3 3-3 3 1.343 3 3z"
/>
<circle fill="#662113" cx={11.5} cy={11.5} r={1.5} />
<circle fill="#662113" cx={24.5} cy={11.5} r={1.5} />
<path
fill="#E1E8ED"
d="M31 25l-3-1-4 6-3-5-2 2-4-2-3 4-3-6-3 2-3.294-7.765C2.249 18.584 2 20.016 2 21.5 2 29.509 9.164 36 18 36s16-6.491 16-14.5c0-1.244-.191-2.444-.517-3.597L31 25z"
/>
</svg>
)

export default SvgChickEgg
4 changes: 3 additions & 1 deletion src/components/Emoji/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import Bird from 'src/components/Emoji/Bird'
import CryingCat from 'src/components/Emoji/CryingCat'
import Question from 'src/components/Emoji/Question'
import Run from 'src/components/Emoji/Run'
import ChickEgg from 'src/components/Emoji/ChickEgg'

export const emojiToComponent = {
bird: Bird,
cryingCat: CryingCat,
question: Question,
run: Run
run: Run,
chickEgg: ChickEgg
}

const Emoji = ({
Expand Down
Loading