Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. // this:
  4.  
  5. type Props1 = Partial<typeof defaultProps1>;
  6.  
  7. const defaultProps1 = {
  8.   prop1: 'default prop val',
  9.   prop2: 'another default',
  10.   prop3: 99,
  11. };
  12.  
  13. // is just a shorthand version of this:
  14.  
  15. type Props2 = Partial<LocalPropsType>;
  16.  
  17. interface LocalPropsType {
  18.   prop1: string;
  19.   prop2: string;
  20.   prop3: number;
  21. }
  22.  
  23. const defaultProps2:LocalPropsType = {
  24.   prop1: 'default prop val',
  25.   prop2: 'another default',
  26.   prop3: 99,
  27. };
  28.  
  29.  
  30. /*
  31.  
  32. It's just a newer typescript pattern that lets you manage fewer interfaces
  33. when you've already got to make a full fledge instances with values anyway.
  34.  
  35. And `<Foo>null` or `null as Foo` is just a standard way of letting the compiler and IDE infer type for object literals.
  36.  
  37. I'm not sure where the problem is. It's just a DRY way of letting typescript handle more of the typing for you that I've always used.
  38.  
  39. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement