View equal.ts
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 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
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
Show hidden characters
{ | |
"extends": "@cutting/eslint-config/react", | |
"rules": { | |
"@typescript-eslint/ban-types": [ | |
"error", | |
{ | |
"types": { | |
"{}": { | |
"message": "Use Record<string, unknown> instead", |
View undefined-order.ts
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 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 UnionTo.ts
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
// 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> = ( | |
( | |
( |
View warehouse.ts
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
// 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 searchresults.json
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
{ | |
"data": { | |
"search": { | |
"repositoryCount": 104, | |
"pageInfo": { | |
"endCursor": "Y3Vyc29yOjEwMA==", | |
"startCursor": "Y3Vyc29yOjE=" | |
}, | |
"nodes": [ | |
{ |
View literal.ts
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
export type PreserveAspectRatioAlignment = | |
| 'xMinYMin' | |
| 'xMidYMin' | |
| 'xMaxYMin' | |
| 'xMinYMid' | |
| 'xMidYMid' | |
| 'xMaxYMid' | |
| 'xMinYMax' | |
| 'xMidYMax' | |
| 'xMaxYMax'; |
View bool-hell.js
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
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
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 Service { | |
name: String! | |
ur!: String! | |
} | |
union Any = String | Float | Int | Boolean | |
type KeyValue { | |
key: String! | |
value: Any |
View .eslint.json
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
{ | |
"extends": "@cutting/eslint-config/react", | |
"rules": { | |
"react-hooks/rules-of-hooks": ["error", { | |
"additionalHooks": "(useIsomorphicLayoutEffect)" | |
}], | |
"react-hooks/exhaustive-deps": ["error", { | |
"additionalHooks": "(useIsomorphicLayoutEffect)" | |
}] |
NewerOlder