Code Monkey home page Code Monkey logo

Comments (5)

runefs avatar runefs commented on August 20, 2024 1

Yeah I kind of guessed that after my last comment. I started thinking about how I would implement the checked type cast. And realized that I wouldn't have the information to do that unless the JS object was bloated with a lot of information, that might have other sever issues. Sorry for (another) none bug :)

from fable-react.

alfonsogarciacaro avatar alfonsogarciacaro commented on August 20, 2024

React helpers like ofType, ofImport, etc (as well as builtins like div, button...) are meant to be uses in a React view function, either nested in another React element (as in div [] [ofType<Test,_,_> props []]) or directly as argument to ReactDom.Render.

According to the signature of ofTypes (and other similar React helpers) the return type of the function is ReactElement and I don't think it's possible to safely cast it to another type.

from fable-react.

runefs avatar runefs commented on August 20, 2024

As I wrote I'd expected that the cast either works and that the methods/properties are then available or that the cast fails, since in all practicalities that is exactly what it does, fails. The result of the above cast is of type ReactElement not 'T

from fable-react.

alfonsogarciacaro avatar alfonsogarciacaro commented on August 20, 2024

Sorry, that would be a separate issue, but concurrently down casting in Fable works the same as in Typescript, meaning there are no runtime checks. This is because down casting is mainly used to interact with dynamic objects coming from JS and also because it's difficult to make proper type testing in many cases (like with interfaces or generic types).

from fable-react.

alfonsogarciacaro avatar alfonsogarciacaro commented on August 20, 2024

No worries! Yes, striking the right balance between good semantics and low overhead in JS runtime is tricky. Actually, you made me realize we need to document better that type casting is not making any runtime checks.

BTW, it's still possible to make type testing in some situations (some primitives and non generic concrete classes).

from fable-react.

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.