Guest User

Untitled

a guest
Dec 11th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. interface Data {
  2. fn(arg: string): Array<string>
  3. fn(arg: number): null
  4. }
  5. let data: Data;
  6. const a = data.fn(42); // null
  7. const b = data.fn("str"); // Array<string>
  8.  
  9.  
  10. interface API {
  11. "/users": { params: [], response: User[]}
  12. "/users/:id": { params: [number], response: User}
  13. }
  14.  
  15. let users: API['/users'] // { params: [], response: User[]}
  16. let user: API['/users/:id'] // params: [number], response: User
  17.  
  18.  
  19. const fn = (arg: 0 | 1) => 42;
  20.  
  21. fn(0); // OK
  22. fn(1); // OK
  23. fn(2); // ERROR Argument of type '2' is not assignable to parameter of type '0 | 1'.
  24. (num: number) => fn(num); // ERROR Argument of type 'number' is not assignable to parameter of type '0 | 1'.
Add Comment
Please, Sign In to add comment