Skip to content

Instantly share code, notes, and snippets.

View Danny101201's full-sized avatar

Danny Danny101201

  • OGG
  • taiwan
  • 19:10 (UTC -12:00)
View GitHub Profile
@Danny101201
Danny101201 / gist:bb71582a8135cd360d12203290d7c900
Last active June 14, 2024 03:08
00018-easy-tuple-length ( type challenge )
import type { Equal, Expect } from '@type-challenges/utils'
const tesla = ['tesla', 'model 3', 'model X', 'model Y'] as const
const spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] as const
// 因為 typeof tesla 或是 spaceX 他們的 type 不是 Array 而是 tuple type
// type Length<T extends ReadonlyArray<T>> = T['length']
// 這題的情況在意的只是 array 的 length 而已,所以我們可以告訴 ts 說放棄判斷 T 是 array 或是 tuple 取而代之的是用 any[] 或是 unknown[]
// type Length<T extends readonly any[]> = T['length']
export function useEmployees() {
const { user } = useAuthentication();
const { client, getRouteURL } = useAPI();
const queryClient = useQueryClient();
/**
* @description API `GET` request for obtaining employees data list.
*/
const getEmployeesList: QueryFunction<Array<APIStoreUserData>> =
useCallback(
import { SetStateAction } from 'react'
import { SearchIcon } from '@chakra-ui/icons'
import { fireEvent, getByAltText, render, screen } from '@testing-library/react'
import { assert, describe, expect, vi } from 'vitest'
import { BaseSelect } from './BaseSelect'
import { colorOptions } from './mockData/data'
describe('BaseSelect', () => {
it('show render in screen', () => {
interface Props {
children: ReactNode;
fallback: (errorMsg: string) => ReactNode
}
interface State {
hasError: boolean;
error: Error | null
}
export const InputModal = ({
modal,
onHide,
orderData,
materialsOptions,
bucketNumOptions,
selectedMasterNumb,
selectedComponentNumb,
selectOrderId,
pouringOptions,
@Danny101201
Danny101201 / next.js proxy
Created October 3, 2022 06:00
next.js proxy
const { createProxyMiddleware } = require('http-proxy-middleware');
const express = require('express');
const next = require('next');
const { version, name } = require('./package.json');
const env = process.env.NODE_ENV;
const dev = env === 'development';
const port = process.env.PORT || 80;
const app = next({
dir: '.', // base directory where everything is, could move to src later
@Danny101201
Danny101201 / webpack-splitChunks
Last active March 18, 2023 05:36
webpack-splitChunks
module.exports = {
optimization: {
// 代碼分割配置
splitChunks: {
chunks: "all", // 對所有模塊進行分割
// 以下是默认值
// minSize: 20000, //分割代碼的最小值
// minRemainingSize: 0, // 確保檔案大小不為0
// minChunks: 1, // 滿足引用次數後進行分割
// maxAsyncRequests: 30, // lazy loading同時加載的最大數量

Zustand 筆記

初始化設定

import create from 'zustand'

interface BearState {
  bears: number
  increase: (by: number) => void
}
@Danny101201
Danny101201 / Typescript tips
Last active July 25, 2022 09:37
Typescript tips
type Features = {
darkMode: () => void;
newUserProfile: () => void;
userManagement: string;
resetPassword: string
}
type OptionalType<T> = {
[key in keyof T]: T[key] extends Function ? T[key] : boolean
}
type OptionalTypeFeaturesOprionalType = OptionalType<Features>
# *** 2022/05/31 起 ***
#
# commit log 請遵造以下格式,並注意冒號後面有一個空格
#
# <type>(<scope> {非必要}): <subject> {必要} (最多 50 個字)
# (一行分行)
# <body> {非必要} (最多 72 個字)
# (一行分行)
# <footer> {非必要}
#