Skip to content

Instantly share code, notes, and snippets.

View pfftdammitchris's full-sized avatar
💭
Dreaming

Christopher Tran pfftdammitchris

💭
Dreaming
View GitHub Profile
@pfftdammitchris
pfftdammitchris / snippet-11.ts
Created January 14, 2026 01:11
5 AI-Powered TypeScript Refactoring Workflows That Save Hours - snippet-11.ts
// Before: Multiple useState = multiple potential renders
const [user, setUser] = useState<User | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<Error | null>(null)
// Async callback triggers 3 separate updates
setLoading(true)
const userData = await api.getUser(userId)
setUser(userData)
setLoading(false)
@pfftdammitchris
pfftdammitchris / snippet-12.ts
Created January 14, 2026 01:11
5 AI-Powered TypeScript Refactoring Workflows That Save Hours - snippet-12.ts
// After: Single useImmer = guaranteed single render per batch
import { useImmer } from 'use-immer'
const [state, updateState] = useImmer({
user: null as User | null,
loading: true,
error: null as Error | null,
})
// All updates batched into ONE render
@pfftdammitchris
pfftdammitchris / snippet-1.ts
Created January 14, 2026 00:55
Code snippets from: 5 AI-Powered TypeScript Refactoring Workflows That Save Hours
// Before: Callback hell
function fetchUserData(userId: string, callback: (err: Error | null, data?: UserData) => void) {
db.getUser(userId, (err, user) => {
if (err) return callback(err)
api.fetchPosts(user.id, (err, posts) => {
if (err) return callback(err)
api.fetchComments(posts[0].id, (err, comments) => {
if (err) return callback(err)
@pfftdammitchris
pfftdammitchris / snippet-1.ts
Created January 14, 2026 00:52
Code snippets from: 5 AI-Powered TypeScript Refactoring Workflows That Save Hours
// Before: Callback hell
function fetchUserData(userId: string, callback: (err: Error | null, data?: UserData) => void) {
db.getUser(userId, (err, user) => {
if (err) return callback(err)
api.fetchPosts(user.id, (err, posts) => {
if (err) return callback(err)
api.fetchComments(posts[0].id, (err, comments) => {
if (err) return callback(err)
@pfftdammitchris
pfftdammitchris / snippet-1.js
Created January 13, 2026 04:44
Code snippets from: Why TypeScript Works Better with AI Coding Tools
// JavaScript - AI has no idea what 'user' contains
function authenticateUser(user, password) {
// AI suggests generic code because it can only guess
if (user && password) {
return validatePassword(user.password, password)
}
}
import type { Options } from 'tsup'
const config: Options = {
//
}
export default config
const config: Options = {
entry: ['src/index.ts'],
dts: true,
sourcemap: true,
format: ['iife', 'cjs', 'esm'],
}
export function sayHello() {
console.log('hello')
}
mkdir my-typescript-library
cd my-typescript-library
const config: Options = {
entry: ['src/index.ts'],
dts: true,
sourcemap: true,
}