Comments (11)
I am using this successfully with Babel 7 (example repo https://github.com/strothj/react-app-rewire-typescript-babel-preset).
Here is the .d.ts file
declare var If: React.SFC<{ condition: boolean }>;
declare var For: React.SFC<{ each: string; index: string; of: Array }>;
declare var Choose: React.SFC;
declare var When: React.SFC<{ condition: boolean }>;
declare var Otherwise: React.SFC;
from jsx-control-statements.
For TS you can use ts-control-statements
from jsx-control-statements.
I've rolled this that provides the same syntax, but for the typescript compiler.
from jsx-control-statements.
Added to readme 😎
from jsx-control-statements.
Since this plugin is a Babel plugin you defintely need to use Babel. You have two options:
- Mature but complex: Use Babel for transpiling JSX code and typescript for transpiling everything else
- Beta but promising: Use Babel7 with TS support
No examples, but maybe a pointer in the right direction?
from jsx-control-statements.
What a shame. I was kinda excited to find this lib expecting it's just set of components that would make my life easier. I am using TypeScript too and I certainly don't want to add Babel into the mix just because of this.
I am not expecting to get a babel free variant here. I am more of curious why this actually need to be a Babel plugin? I mean is there really that much of performance gain by transpiling this?
from jsx-control-statements.
The babel plugin isn't actually for performance, it's because the interior of a React component gets executed even if it's not rendered: https://github.com/AlexGilleran/jsx-control-statements/wiki/Why-Transform.
I've been thinking you could do a lot of this with render props at the cost of slightly uglier syntax, but haven't gotten around to it :(.
from jsx-control-statements.
I see now, thanks for the explanation. Haven't really thought about this issue before, it's kinda eye opener :) That link to the wiki should probably be in readme, not many people will check wiki imo.
I was kinda thinking about using this more for a boolean value checks then for existence checks, but I can get away by making my own component for that. Doing this with render props would not probably make sense, it would get too bloated. Personally I have a limit of 2 render prop component in a single jsx tree.
It's a pity that TypeScript plugin system cannot really do what Babel can. It's not possible to extend syntax in any way. Well, perhaps it's a good thing also as it keeps the code consistent without surprises.
from jsx-control-statements.
whoa! rad!
from jsx-control-statements.
from jsx-control-statements.
@AlexGilleran would you consider adding the tsx syntac to the for statement?
<For of={names} body={(name, i) => (
<li key={name}>
{i}<string>{name}</strong>
</li>
)} />
The work of @KonstantinSimeonov is pretty amazing, but it does not allow to be used with babel-loader which effectively makes things complicated around CRA.
from jsx-control-statements.
Related Issues (20)
- The control statements don't narrow TypeScript types HOT 1
- TypeScript type for children is missing a render function HOT 1
- TChildren conflicts with ReactNode children HOT 2
- Why do we need ```transform-react-inline-elements``` plugin ?
- Switch-case style control statement HOT 2
- Problem with ./node_modules/tsx-control-statements/components.ts HOT 3
- Typo error HOT 1
- Support babel macros HOT 2
- conditional statements don't work unless wrapped in brackets. is this supposed to happen? HOT 1
- Not working with laravel-mix with webpack config
- Can you provide plugins for swc HOT 1
- Can you provide a version based on swc core? HOT 1
- Uncaught ReferenceError: For is not defined HOT 5
- Not working with create-react-app HOT 7
- If is not defined HOT 4
- App breaks if i try to directly access the url - With Error - Choose is not defined HOT 1
- React-Native:Installation-Guide HOT 2
- last published version is 3 years old HOT 2
- ESLint autofix HOT 2
- Undefined is not a function with new JSX transform with react 17 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 jsx-control-statements.