Last active
December 18, 2018 08:27
-
-
Save przemyslawjanpietrzak/68f7908e591a101c0447c744278f9dff to your computer and use it in GitHub Desktop.
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
interface Data { | |
fn(arg: string): Array<string> | |
fn(arg: number): null | |
} | |
let data: Data; | |
const a = data.fn(42); // null | |
const b = data.fn("str"); // Array<string> | |
interface API { | |
"/users": { params: [], response: User[]} | |
"/users/:id": { params: [number], response: User} | |
} | |
let users: API['/users'] // { params: [], response: User[]} | |
let user: API['/users/:id'] // params: [number], response: User | |
const fn = (arg: 0 | 1) => 42; | |
fn(0); // OK | |
fn(1); // OK | |
fn(2); // ERROR Argument of type '2' is not assignable to parameter of type '0 | 1'. | |
(num: number) => fn(num); // ERROR Argument of type 'number' is not assignable to parameter of type '0 | 1'. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment