Comments (5)
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.
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.
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.
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.
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)
- React Server Components integration HOT 2
- Can't figure out how to wrap my view with a Higher Order Component HOT 4
- JsInterop helper for wrapping a higher order component HOT 2
- Can't reference React in Fable HOT 2
- Fable.ReactServer.cssProp very slow HOT 4
- Add Custom DU to DOMAttr HOT 1
- FunctionComponent.Lazy and SSR HOT 1
- Update samples to Fable 3
- ReactDOM.hydrate is no longer supported in React 18 HOT 17
- Can't update shared state passed with useContext? HOT 3
- Q: Use ReactElement import member for Storybook HOT 3
- Missing 'open' from Fable.React.Props? HOT 2
- Last Fable.React upgrade breaks my code HOT 7
- Publish source files from Fable.React.Types and Fable.ReactDom.Types to nuget HOT 5
- Fable.React version 8 depends on React.Dom gte 18 lt 19 according to femto
- Add Pointer Events HOT 3
- Why is useCallback not implemented? HOT 3
- How to obtain a component ref in a function component? HOT 5
- FunctionComponent.Of functions cache breaks reusable code HOT 1
- voidEl breaks with: $ELEMENT is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fable-react.