-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript typings #90
Comments
Aren't people usually including something like |
Yep flow, closure compiler and I suppose TS support external declarations |
Yes, |
sry for off topic, but how are u using it with typescript @timsuchanek ? you are double transpiling? TS -> Babel ( because according to docs, you need babel styled-jsx plugin ) |
@Hotell Indeed, so first I'm transpiling with |
That brings up the question if import Style from 'styled-jsx/component'
const IAmRed = () => (
<div>
<p>I'm red</p>
<Style>{`p { color: red; }`}</Style>
<Style global>{`body { background: white; }`}</Style>
</div>
) This might be more according to React standards and doesn't interfere with native elements. |
@nikvm the issue is that that makes me think the component is standalone, but in reality it requires transpilation. It's actually less intuitive. Good discussion to have though |
I took advice from @timsuchanek and simply put this in my code, in import 'react'
// Augmentation of React
declare module "react" {
interface HTMLProps<T> {
jsx?: boolean;
global?: boolean;
}
} It works like a charm! |
Thanks for the explanation @timsuchanek. Couldn't figure out why it wasn't working, reconfigured webpack to let babel do the jsx transpiling, not awesome-typescript-loader, like you described, working great now. |
Regarding to typescript and
|
I was able to fix it with: // custom.d.ts
import 'react';
declare module 'react' {
interface StyleHTMLAttributes<T> extends React.HTMLAttributes<T> {
jsx?: boolean;
global?: boolean;
}
} |
@nikvm can it actually be used like that? I’m searching for a solution that does not require Babel and can go pure Typescript |
Hi, thanx for the fix, but I can't make it work. My {
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"jsx": "react",
"allowJs": true,
"typeRoots": [
"node_modules/@types",
"./typings"
]
},
"exclude": [
"next.config.js"
]
} I'm very fresh with typescript, sorry for bothering |
Now,I have resolve the error "Property 'jsx' does not exist on type ".But I still can not make styled-jsx work with the awesome-typescript-loader.My webpack.config.js is showed below: |
check out DefinitelyTyped/DefinitelyTyped#22181 |
added more typings in this PR. Would appreciate @giuseppeg's review extension of react |
@giuseppeg This issue could be closed as DefinitelyTyped/DefinitelyTyped#22516 was merged and typings already available under |
Hi, I installed My tsconfig.json is:
The component which style is not applied is this file: https://github.com/1kohei1/sd-scheduler/blob/master/front/components/MyLayout.tsx |
@1kohei1 you are trying to pass |
@a-ignatov-parc Ok! Thank you! I decided to apply style by |
Has anyone managed to use styled-jsx with typescript and CSS in separate file? Here it looks like they did that, but it doesn't work for me, I'm not sure this test really passed. I get the same error like mentioned in the referenced issue #381 |
How write this for Inferno?
|
@R1ZZU can you help these folks? |
Found my way here because I'm having trouble with One part of the problem is a PR I submitted to DefinitelyTyped here, to properly represent The second problem is that, while I have no problem in Next 5 or 6 building pages that render in the browser with styled-jsx and TypeScript, I cannot get It looks like the upcoming release rethinks You can reproduce all the issues I'm talking about at this repo, across its various branches: https://github.com/bensaufley/styled-jsx-example-issues/
|
Following up on the first issue, |
@timsuchanek - Just want to say a belated thanks for your Of course, it was because Typescript was already transforming JSX -> IMO, this could do with being featured under a 'Using with Typescript' section in the readme. |
…ercel/styled-jsx#90 (comment)) htbkoo/AnalyticsAndAdsSpike
Hi, I am hitting this issue with wrong scoping: https://spectrum.chat/styled-jsx/general/storybook-next-js-styled-jsx-styles-not-scoped-to-component~8a63d2a1-6b05-4a27-b839-c4a903eb6f43
Edit: ok got it it's actually similar to "Warning: unknown jsx prop on <style> tag" issue. When TS is configured right, it does not complain about "jsx" tag. But it won't build correctly either. An additional step of running Babel for .ts file, with Webpack Babel-loader, is probably mandatory (setting .babelrc is not enough). As far as I understand you actually need TS code to be transpiled with |
hei, i'm using CRA typescript template. i've tried // custom.d.ts
import "react";
declare module "react" {
interface StyleHTMLAttributes<T> extends React.HTMLAttributes<T> {
jsx?: boolean;
global?: boolean;
}
} however i'm getting
any other workarounds? |
@cmnstmntmn I struggled with the same issue. I am using create-react-library, so my solution might work for you as well. For me, the combination that seemed to work was the two fixes that you use above, plus adding a
Hope this works for you as well. I spent many hours banging my head against this one before coming up with something that appears to work... |
Thank you @smeijer
|
First of all, awesome tool!
We're using it together with TypeScript and it works like a charm.
However,
jsx
andglobal
are no standard html attributes, so the React Typings don't include them and the TypeScript compiler throws errors.That can easiliy be fixed with these 2 additions:
DefinitelyTyped/DefinitelyTyped@master...timsuchanek:patch-1
What are your ideas on it? Is there another way to make it work with TypeScript?
Thanks
The text was updated successfully, but these errors were encountered: