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
Show hidden characters
| { | |
| "compilerOptions": { | |
| "target": "es5", | |
| "module": "commonjs", | |
| "lib": ["es2015", "dom"], | |
| "outDir": "../../lib/client", | |
| "composite": true, | |
| "strict": true, | |
| "esModuleInterop": true | |
| }, |
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 Props = { | |
| title?: string; | |
| }; | |
| class Heading extends React.Component<Props> { | |
| static defaultProps = { | |
| title: 'Hello!' | |
| }; | |
| render() { | |
| const title = this.props.title; |
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 Props = { | |
| title?: string; | |
| }; | |
| class Heading extends React.Component<Props> { | |
| static defaultProps = { | |
| title: 'Hello!' | |
| }; | |
| render() { | |
| const title = this.props.title; |
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 * as ReactDOM from 'react-dom'; | |
| class Heading extends React.Component { | |
| render() { | |
| return <h1>{this.props.title.toUpperCase()}</h1> | |
| } | |
| } | |
| Heading.defaultProps = { title: 'Hello!' }; |
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 a1: any = 'a'; | |
| const a2: unknown = 'a'; | |
| a1.length; // = 1 | |
| a2.length; // compiler error | |
| a1(); // error during execution | |
| a2(); // compiler error | |
| new a1(); // error during execution | |
| new a2(); // compiler error | |
| const a3 = a1 + 3; // = 'a3' | |
| const a4 = a2 + 3; // compiler error |
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
| function compose2<T1 extends any[], T1R, T2>(f1: (...args1: T1) => T1R, f2: (arg: T1R) => T2) { | |
| return (...a: T1) => f2(f1(...a)); | |
| } | |
| const add = (x: number, y: number) => x + y; | |
| const sqr = (x: number) => x * x; | |
| const addAndSqr = compose2(add, sqr); | |
| addAndSqr(1, 2); // valid | |
| addAndSqr('a', 2); // invalid type |
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
| function hello(...args: [string, number, number, ...string[]]): string { | |
| return args.join(','); | |
| } |
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
| // JavaScript | |
| function jsHello() { | |
| return [...arguments].join(','); | |
| } | |
| // JavaScript, second way | |
| function jsHello1(...args) { | |
| return args.join(','); | |
| } |
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 Strings = [...string]; | |
| type Empty = []; | |
| const c1: Strings = ['a', 'b']; | |
| const c2: Strings = []; | |
| const c3: Empty = []; | |
| const c4: Empty = ['a', 'b']; // invalid type |
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 StringAndNumbers = [string, ...number[]]; | |
| const b1: StringAndNumbers = ['a', 1, 2, 3]; | |
| const b2: StringAndNumbers = ['a']; |