GithubHelp home page GithubHelp logo

TypeSafe values? about react-css-grid HOT 1 CLOSED

httpete avatar httpete commented on August 17, 2024
TypeSafe values?

from react-css-grid.

Comments (1)

aboyce avatar aboyce commented on August 17, 2024

Hello,

I agree they are more disappointing that I would have liked/hoped. As you mentioned, the library depends on csstype to tackle this. The library was mainly chosen because it is what React itself uses for its style prop under the hood, so it makes sense to use it for React component libraries for compatibility and an assumption that it is the best solution they could find.

After some thought, I'm guessing the main issue on why it's so loosely typed is because of the vast number of options.

If you consider something simple like padding, it has to support:

  • style={{ padding: 1 }} which translates to padding: 1px;
  • style={{ padding: '1px' }} which also translates to padding: 1px;
  • style={{ padding: '1em' }} which translates to padding: 1em;
  • style={{ padding: '1pt' }} which translates to padding: 1pt;
  • style={{ padding: '1pc' }} which translates to padding: 1pc;
  • ...

And that doesn't include the shortcuts such as style={{ padding: '5em 10em' }} or style={{ padding: '1em 2em 3em 4em' }}.

So the type would have to be number, or strings that are a number followed by px or em or pt... , and then these combined into a possible pair or as a four.

I'm not sure there is any valid way to do this in Typescript other than a list of all possible values such as '1px' | '2px' | '3px' and so on. I found that with the fairly limited number of conditional type definitions I included in these libraries, I had to put a disclaimer in the README as it was starting to overwhelm VS Code with the conditional type suggestion.

I think the best we could realistically hope for are console warnings at development time using regexes or something?

Apologies I've not really provided a solution 😕

from react-css-grid.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.