GithubHelp home page GithubHelp logo

Improve IStyle type about fela HOT 5 CLOSED

hedwiggggg avatar hedwiggggg commented on July 17, 2024
Improve IStyle type

from fela.

Comments (5)

hedwiggggg avatar hedwiggggg commented on July 17, 2024

Experimented a bit.

This could be a implementation for the new IStyle:
Playground Link

And this for the new IStyle, using fela-plugin-fallback-value:
Playground Link

from fela.

hedwiggggg avatar hedwiggggg commented on July 17, 2024

And as you can see here: Playground Link

This change shouldn't break anything, because the legacy nested prop would still be possible.

from fela.

hedwiggggg avatar hedwiggggg commented on July 17, 2024

Thought about it a little bit more, there is a downside, called declaration merging, see here (typescript docs).

The problem with that is, that plugins can't extend the IStyle type anymore.
Didn't happened yet, but would be nice for the legacy fela-plugin-typescript types and neccessary when using fela-plugin-fallback-value.

Came up with a workaround, seems to be working fine: Playground Link

from fela.

hedwiggggg avatar hedwiggggg commented on July 17, 2024

Using these changes in my project I've discovered a weird behavior using the declaration merging for the plugins.
Guess it's because an empty interface is equivalent to {}, which is equivalent to "any non-nullish value".

That lead to the following behaviour:

const _test: IStyle = []; // ok, but should throw an error

This can be fixed by providing an optional 'brand' property, so the empty Extension interface won't be equal to {}.

See Playground Link

Edit: Updating the PR now.

from fela.

hedwiggggg avatar hedwiggggg commented on July 17, 2024

Found another small bug, demonstrated here:

Playground Link

Edit:

And another related bug: Playground Link

Got this as a workaround: Playground Link

Im just exposing IStylePrimitiveExtension as a mergable type. So plugins could hook into that, to extend the primitive type.
For example the following case: Playground Link

from fela.

Related Issues (20)

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.