Skip to content

Instantly share code, notes, and snippets.

View tscpp's full-sized avatar

Elias Skogevall tscpp

  • Sweden
  • 02:43 (UTC +02:00)
View GitHub Profile
/**
* Wether the property is optional in the object or not.
*
* @example ```
* type Foo = PropertyRequirement<{ a: number }, 'a'>; // 'required'
* type Bar = PropertyRequirement<{ b?: number }, 'b'>; // 'optional'
* ```
*/
type PropertyRequirement<T, K extends keyof T> = Pick<T, K> extends Required<
Pick<T, K>
@tscpp
tscpp / overload_arguments_as_union.d.ts
Last active April 3, 2022 15:47
Function overload arguments (max 50) as unions
// Function overload arguments (max 50) as unions.
// Note that the size of this file is 32kb!
type ParametersOfOverloads<T>=T extends{(..._:infer A):unknown;(..._:infer B):unknown;(..._:infer C):unknown;(..._:infer D):unknown;(..._:infer E):unknown;(..._:infer F):unknown;(..._:infer G):unknown;(..._:infer H):unknown;(..._:infer I):unknown;(..._:infer J):unknown;(..._:infer K):unknown;(..._:infer L):unknown;(..._:infer M):unknown;(..._:infer N):unknown;(..._:infer O):unknown;(..._:infer P):unknown;(..._:infer Q):unknown;(..._:infer R):unknown;(..._:infer S):unknown;(..._:infer T):unknown;(..._:infer U):unknown;(..._:infer V):unknown;(..._:infer W):unknown;(..._:infer Q):unknown;(..._:infer Y):unknown;(..._:infer Z):unknown;(..._:infer a):unknown;(..._:infer b):unknown;(..._:infer c):unknown;(..._:infer d):unknown;(..._:infer e):unknown;(..._:infer f):unknown;(..._:infer g):unknown;(..._:infer h):unknown;(..._:infer i):unknown;(..._:infer j):unknown;(..._:infer k):unknown;(..._:infer l):unknown;(..._:infer m)
@tscpp
tscpp / require-statement-regex.txt
Last active November 29, 2020 17:45
Regex that can be used to replace require statements with ES6 import statements
Find: (^|\n)\s*(?:let|const|var)\s+(.+?)\s*=\s*require\s*\(\s*(?:'|")(.+?)(?:'|")\s*\)\s*(;(?:$|\n)|(?:$|\n))
Replace: $1import * as $2 from '$3'$4
import NSwag from 'nswagjs'
import * as path from 'path'
import * as protoc_swagger_gen from '@accility/protoc-swagger-plugin'
import * as protoc_tools from '@accility/protoc-tools'
import * as protoc_apis from 'google-proto-files'
import * as fs from 'fs'
const PATH2GENERATED = path.join(__dirname, 'generated')
const PATH2PROTO = path.join(__dirname, 'protos')
const PATH2NSWAG = path.join(__dirname, 'node_modules/nswag')