Skip to content

Instantly share code, notes, and snippets.

@floatrx
Last active October 15, 2024 11:53
Show Gist options
  • Save floatrx/e191fee08498aff5c138e1243b1b2fde to your computer and use it in GitHub Desktop.
Save floatrx/e191fee08498aff5c138e1243b1b2fde to your computer and use it in GitHub Desktop.
Global type definitions
import React from 'react';
// .env
declare namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'test';
}
}
// Global type declarations for React components
declare global {
// Just empty object
type EmptyObj = Record<string, unknown>;
// Any object
type AnyObj = Record<string, any>;
// React fn component with children
type FC<T = object> = React.FunctionComponent<React.PropsWithChildren<T>>;
// React fn component without children
type RC<T = object> = React.FunctionComponent<T>;
// Get available props from element (e.g. button, input, div, etc.)
type ComponentProps<T> = React.ComponentProps<T>;
// Next page props
type PageProps<Params = EmptyObj, SearchParams = EmptyObj> = {
params: Partial<Params>;
searchParams: Partial<SearchParams>;
};
}
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "./global.d.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 3001,
proxy:
process.env.NODE_ENV === 'development'
? {
'/api': {
target: 'http://localhost:3000', // for example
changeOrigin: true,
},
}
: {},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment