Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul dagda1

View GitHub Profile
View equal.ts
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false
type Test1 = Equal<[1, 2, '3'], [1, 2, '3']>
// ^? - type Test1 = true
type Test2 = Equal<[1, 2, '3'], [1, 2, 3]>
// ^? - type Test2 = false
View .eslintrc.json
{
"extends": "@cutting/eslint-config/react",
"rules": {
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"{}": {
"message": "Use Record<string, unknown> instead",
View UnionTo.ts
// both examples below start
type UnionToXXX<T> = (T extends any ? (t: T) => T : never) extends infer U ? // rest
// Converts { x: string } | { y: number } to { x: string, y: number }
type UnionToIntersection<T, U = T> = (U extends any ? (arg: U) => any : never) extends ((arg: infer I) => void) ? I : never;
// Converts string | number | boolean to [string, number, boolean]
type UnionToTuple<T> = (
(
(
@dagda1
dagda1 / undefined-order.ts
Created Feb 7, 2022
Extend undefined order
View undefined-order.ts
type BadUndefinedKeys<T> = {
[P in keyof T]-?: T[P] extends undefined ? P : never
}[keyof T];
type Bad = BadUndefinedKeys<{ foo: number, bar?: string}>; // never
type GoodUndefinedKeys<T> = {
[P in keyof T]-?: undefined extends T[P] ? P : never;
}[keyof T];
View warehouse.ts
// HERE IS MY ANSWER WITH THE TIME CONSTRAINT REMOVED
// https://github.com/dagda1/guardian-interview/blob/v0/src/index.ts
import inquirer from 'inquirer';
const { prompt } = inquirer;
const commands = ['N', 'S', 'E', 'W'] as const;
type RobotState = 'IDLE' | 'CARRYING';
View Microsoft.PowerShell_profile.ps1
$snapins = Get-PSSnapin -Registered
$snapins | Add-PSSnapin
Get-Module -ListAvailable | Import-Module
Get-PSSnapin | Format-Table -autosize PSVersion, Name
Get-Module | Format-Table -autosize ModuleType, Name
function ff ([string] $glob) { get-childitem -recurse -include $glob }
View searchresults.json
{
"data": {
"search": {
"repositoryCount": 104,
"pageInfo": {
"endCursor": "Y3Vyc29yOjEwMA==",
"startCursor": "Y3Vyc29yOjE="
},
"nodes": [
{
View literal.ts
export type PreserveAspectRatioAlignment =
| 'xMinYMin'
| 'xMidYMin'
| 'xMaxYMin'
| 'xMinYMid'
| 'xMidYMid'
| 'xMaxYMid'
| 'xMinYMax'
| 'xMidYMax'
| 'xMaxYMax';
View bool-hell.js
let isActive
if (inactive === false || (active && !inactive)) {
isActive = true
} else if (active === false || (inactive && !active)) {
isActive = false
}
// mutually exclusive string union cures this
// type State = 'ACTIVE' | 'INACTIVE';
View simulation.graphql
type Service {
name: String!
ur!: String!
}
union Any = String | Float | Int | Boolean
type KeyValue {
key: String!
value: Any