This file contains hidden or 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
| // Paste this to typescriptlang.org/play or click the link the comments | |
| type Expected = { | |
| a: 1 | 2 | |
| b?: 1 | 2 | |
| c?: 1 | |
| d?: 1 | 2 | |
| e: 2 | |
| f?: 2 | |
| } |
This file contains hidden or 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
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta | |
| name="viewport" | |
| content="width=device-width, initial-scale=1, shrink-to-fit=no" | |
| /> | |
| <meta name="theme-color" content="#ffffff" /> | |
| <meta | |
| name="description" |
This file contains hidden or 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 definitions for meow 5.x | |
| // Project: https://github.com/sindresorhus/meow | |
| // Definitions by: KnisterPeter <https://github.com/KnisterPeter> | |
| // Lindsey Smith <https://github.com/praxxis> | |
| // Jason Dreyzehner <https://github.com/bitjson> | |
| // TODO?? hasparus <https://github.com/hasparus> | |
| // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | |
| // TypeScript Version: 3.4 | |
| import * as buildOptions from "minimist-options"; |
This file contains hidden or 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 * as assert from 'assert'; | |
| // @types/mysql QueryOptions | |
| type QueryOptions = { | |
| sql: string; | |
| values: unknown[]; | |
| }; | |
| const brand = Symbol('sql-brand'); |
This file contains hidden or 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 { PubSub } from 'graphql-subscriptions'; | |
| type PubSubAction = [typeof MESSAGE_ADDED, MessageAddedPayload] | ['foo', 121]; | |
| type UnionToIntersection<U> = | |
| (U extends any ? (k: U) => void : never) extends | |
| ((k: infer I) => void) ? I : never; | |
| type PairsToRecord<Pair extends [string, any]> = | |
| Pair extends [infer T1, infer T2] |
This file contains hidden or 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 createStore from 'zustand'; | |
| export const [useStore, _store] = createStore(set => ({ | |
| foo: 2, | |
| actions: { | |
| setFoo: (newFoo: number) => { | |
| set({ foo: newFoo }); | |
| }, | |
| }, | |
| })); |
This file contains hidden or 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 React, { useEffect, useRef } from 'react'; | |
| import { render } from 'react-dom'; | |
| type ZustandStore = ReturnType<typeof import('zustand').default>[1]; | |
| /** | |
| * @example | |
| * const [useStore, store] = createStore(set => { /* ... */ }); | |
| * if (process.env.NODE_ENV === 'development') { | |
| * zustandDevtools.mountStoreSinkDevtool('MyStore', store); |
This file contains hidden or 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
| // components.ts | |
| type Component = Components[keyof Components]; // Health | Transform | |
| interface Components { /* add new components to this interface in separate files */ } | |
| // health.ts | |
| type Health = number & { __brand: 'Health' }; | |
| interface Components { | |
| health: Health; |
This file contains hidden or 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 Primitive = string | number; | |
| type Constructor<T, Args extends any[]> = { | |
| new (...args: Args): T; | |
| (...args: Args): T; | |
| }; | |
| function makeConstructor< | |
| T, |
This file contains hidden or 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 Constructor<T, Args extends any[]> = { | |
| new (...args: Args): T; | |
| (...args: Args): T; | |
| }; | |
| function makeConstructor<T, Args extends any[], P = {}>( | |
| create: (...args: Args) => T, | |
| prototype?: P & ThisType<T & P> | |
| ) { | |
| const constructor = function(this: T | undefined, ...args: Args) { |