This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from 'react'; | |
import { z } from 'zod'; | |
import reactLogo from './assets/react.svg'; | |
import './App.css'; | |
import { useZodForm, register } from './useZodForm'; | |
type ObjectKey = keyof any; | |
type Field<N extends ObjectKey, V> = { | |
name: N; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
const { execSync } = require('child_process'); | |
const { ESLintUtils, AST_NODE_TYPES } = require('@typescript-eslint/utils'); | |
/** @type {Record<string, { exportName: string, usedInModule: boolean }[]>} */ | |
let cache; | |
const loadUnusedExports = () => { | |
if (!cache) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
const { execSync } = require('child_process'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const { parse } = require('@typescript-eslint/parser'); | |
const eslintRc = require('../.eslintrc.js'); | |
const unusedExportsByFilename = execSync('ts-prune') | |
.toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
/** @type {import('@typescript-eslint/utils').TSESLint.RuleModule} */ | |
module.exports = { | |
meta: { | |
docs: { | |
description: | |
"See [TypeScript Enums are TERRIBLE. Here's Why. - Michigan TypeScript](https://www.youtube.com/watch?v=0fTdCSH_QEU)", | |
}, | |
type: 'suggestion', | |
fixable: 'code', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function complement<A, T extends A>(predicate: (arg: A) => arg is T): (arg: A) => arg is Exclude<A, T>; | |
function complement<A extends any[]>(predicate: (...args: A) => boolean) { | |
return (...args: A) => !predicate(...args); | |
} | |
function isUndefined<A>(anything: A | undefined): anything is undefined; | |
function isUndefined(anything: any): anything is undefined { | |
return anything === undefined | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isCapitalized = (str) => str[0] === str[0].toUpperCase(); | |
const reportPropsError = (componentName, node, context, sourceCode) => { | |
const newPropsName = `${componentName}Props`; | |
const allPropsIdentifierTokens = sourceCode.ast.tokens.filter( | |
(token) => token.type === 'Identifier' && token.value === 'Props' | |
); | |
context.report({ | |
node, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global.d.ts | |
declare global { | |
// eslint-disable-next-line @typescript-eslint/ban-types | |
type EmptyObject = Record<string, never>; | |
} | |
// .eslintrc.js | |
'@typescript-eslint/ban-types': [ | |
2, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const packageLockJson = require('./package-lock.json'); | |
const packageJson = require('./package.json'); | |
const compareVersions = (ver1, ver2) => { | |
const v1 = ver1.split('.'); | |
const v2 = ver2.split('.'); | |
return v1.some((v, i) => Number(v) > Number(v2[i])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FilterUnion<T extends string, Keys extends string> = { | |
[Key in Keys extends infer R ? (R extends `${string}${T}${string}` ? R : never) : never]: string; | |
} extends infer O | |
? keyof O | |
: never; | |
export const stringIncludes = <T extends string>(text: T) => <S extends string>( | |
str: S | |
): str is FilterUnion<T, S> => str.includes(text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const { mapValues } = require('lodash'); | |
const lock = require('./package-lock.json'); | |
const pack = require('./package.json'); | |
const newDependencies = mapValues( | |
pack.dependencies, | |
(depVersion, depName) => lock.dependencies[depName].version | |
); | |
const newDevDepencies = mapValues( |