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 Pick<T, K extends keyof T> = { | |
| [P in K]: T[P]; | |
| }; |
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
| class Settings { | |
| setting1: boolean = true; | |
| setting2: string = ''; | |
| setting3: number = 1; | |
| constructor(obj: Partial<Settings>) { | |
| Object.assign(this, obj); | |
| } | |
| } | |
| const obj = new Settings({ setting3: 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
| type Partial<T> = { | |
| [P in keyof T]?: T[P]; | |
| }; | |
| type Required<T> = { | |
| [P in keyof T]-?: T[P]; | |
| }; | |
| type Readonly<T> = { | |
| readonly [P in keyof T]: T[P]; | |
| }; |
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
| const dict2: { a?: string } & Record<string, number> = {}; | |
| dict2.a = 'a'; | |
| dict2.a = 1; // ERROR: 1 is not assignable to type string | |
| dict2.b = 2; | |
| dict2.b = 'b'; // ERROR: "b" is not assignable to type number |
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
| const dict: Record<string, number> = {}; | |
| dict.a = 1; | |
| dict.b = 'a'; // ERROR: "a" is not assignable to type number |
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 Record<K extends keyof any, T> = { | |
| [P in K]: 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
| import * as React from "react"; | |
| import { inject, injectable } from "inversify"; | |
| import { connect } from "react-inversify"; | |
| import { IProvider } from "./providers"; | |
| type Props = { | |
| nameProvider: IProvider<string>; | |
| }; | |
| @injectable() |
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 React from "react"; | |
| import { resolve } from "inversify-react"; | |
| import { IProvider } from "./providers"; | |
| export class Hello extends React.Component { | |
| @resolve("nameProvider") private readonly nameProvider: IProvider<string>; | |
| render() { | |
| return <h1>Hello {this.nameProvider.provide()}!</h1>; | |
| } |
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 React from "react"; | |
| import { lazyInject } from "./ioc"; | |
| import { IProvider } from "./providers"; | |
| export class Hello extends React.Component { | |
| @lazyInject("nameProvider") private readonly nameProvider: IProvider<string>; | |
| render() { | |
| return <h1>Hello {this.nameProvider.provide()}!</h1>; | |
| } |
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 React from "react"; | |
| import { IProvider } from "./providers"; | |
| export class Hello extends React.Component { | |
| private readonly nameProvider: IProvider<string>; | |
| render() { | |
| return <h1>Hello {this.nameProvider.provide()}!</h1>; | |
| } | |
| } |