Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this:
- type Props1 = Partial<typeof defaultProps1>;
- const defaultProps1 = {
- prop1: 'default prop val',
- prop2: 'another default',
- prop3: 99,
- };
- // is just a shorthand version of this:
- type Props2 = Partial<LocalPropsType>;
- interface LocalPropsType {
- prop1: string;
- prop2: string;
- prop3: number;
- }
- const defaultProps2:LocalPropsType = {
- prop1: 'default prop val',
- prop2: 'another default',
- prop3: 99,
- };
- /*
- It's just a newer typescript pattern that lets you manage fewer interfaces
- when you've already got to make a full fledge instances with values anyway.
- And `<Foo>null` or `null as Foo` is just a standard way of letting the compiler and IDE infer type for object literals.
- 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.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement