question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a guideline for typings

See original GitHub issue

As we are moving towards full typescript, would be good to set some guidelines of “best” practices, or at least what we think that is good/readable. This will help during the conversion of all the components to TS and also when new components are created.

I’m leaving as an inspiration, the bare-bone that webpack had created when they started to add types to their codebase, it think that it is such a good start.

https://github.com/webpack/webpack/issues/7122

What are your thoughts about it? Let’s discuss!!


Guidelines so far:

When you have scenarios like:

const C = Card as typeof Card & CardComponents;

C.Fit = CardFit;

export * from "./Card";

export default C;

It is prefered to use the following:

export * from "./Card";
export * from "./CardFit";

export default Object.assign(Card, {
  Fit: CardFit
});

  • Always export prop types:

    export interface DividerProps {
      vertical?: boolean;
    }
    
  • Always export default and * from component files (that will export types):

    import Divider from "./Divider";
    export * from "./Divider";
    export default Divider;
    
  • If it’s a component that renders another component (wrapper), we must extend props interface:

    import Box, { BoxProps } from "../Box";
    
    export interface DividerProps extends BoxProps {
      vertical?: boolean;
    }
    
    const DividerComponent = (props: DividerProps) => <Box {...props} />;
    

When you have: const component = (props: CodeProps) => ....

Turn into: const CodeComponent = (props: CodeProps) => ...

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:16 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
renatoribcommented, Sep 24, 2018
3reactions
diegohazcommented, Oct 4, 2018
  • Always export prop types:

    export interface DividerProps {
      vertical?: boolean;
    }
    
  • Always export default and * from component files (that will export types):

    import Divider from "./Divider";
    export * from "./Divider";
    export default Divider;
    
  • ~If it’s a component that renders another component (wrapper), we must extend props interface~ Always extend prop types from the component being used:

    import Box, { BoxProps } from "../Box";
    
    export interface DividerProps extends BoxProps {
      vertical?: boolean;
    }
    
    const DividerComponent = (props: DividerProps) => <Box {...props} />;
    
Read more comments on GitHub >

github_iconTop Results From Across the Web

typing Guidelines - Sense-Lang
Learn to practice typing using various types of tutorials and keyboard layouts. Soon enough, the keyboard will become a part of your hand!...
Read more >
How to Type: 15 Steps (with Pictures) - wikiHow
1. Place your fingers in the "home" position. That's the position in which your fingers will rest between keystrokes. No matter what part...
Read more >
5 Typing tips for beginners and students
Technique is so important when you are learning how to type. Try these typing tips for beginners and start improving your skills today....
Read more >
Creating a 'How to' Guide - University of Bath
When to create a 'How to' Guide; Writing your 'How to' Guide; Enquiries ... the right Guide type, and writing your Guide summary,...
Read more >
Practice typing the right way - TypingAcademy
The guide to our typing tutor. To use our online typing tutor, you don't have to read these instructions first. However, many users...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found