-
Notifications
You must be signed in to change notification settings - Fork 48
Integration with Typescript (TSX) #22
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
Comments
Does this plug support TSX? |
You could add a definition file that declares |
Need help here. @ForbesLindesay Can you please give a snippet or example? |
Just add |
@ForbesLindesay
file A.tsx import * as React from 'react';
class A extends React.PureComponent {
render() {
return pug`
div 12234
`;
}
}
export default A; In my project "transform-react-jsx" seems could not transform tsx..... |
I don't know what could be causing that. I've never seen it be an issue before. It looks more like a problem with babel, than typescript. |
@ForbesLindesay Just adding
It'll run the typescript loader first and when it doesn't find pug variable defined it throws an error at compile time only. That's the whole problem. |
Never mind, it is working now. |
@param-fk and to anyone who got TS with this working. I couldn't get them to work and I tried all options:
With any option I end up with an error stating that the React components in the pug template strings are not recognized, e.g. Uncaught ReferenceError: BrowserRouter is not defined. My Webpack config with option 2 is:
|
@param-fk how you made it work! I am still stuck on the same error for the same reason |
even i am stuck with same error please explain how you did this? |
@param-fk please explain how you did this? |
This is the problem I have encountered: import { Header } from './components'
console.log(Header) // produce a side effect
export function Main(props) {
return pug `
Header
`
} It works just fine, but when I remove Because the source code is through Typescript first and Typescript does not handle Does anyone know how to solve this? Thx. |
My suggestion would be to use babel to compile your TypeScript via https://babeljs.io/docs/en/babel-preset-typescript and use the typescript CLI just for type checking (by passing |
Blocked by microsoft/TypeScript#9191 |
So would this mean that pug needs to be transformed before the typescript ? |
Yes, using a custom transformer so that it ends up being a valid JSX node and TS will be able to recognize this block of Pug code and the components as valid references, so that no elision is gonna happen |
I publish a library to solve this problem. |
trying to get expo / react-native / typescript / pug to work having a hard time... it is saying |
We should include wisdom from this thread in the README |
I am trying to use pug in my Typescript React components like your basic example:
The problem is that I can't get it to work because the typescript loader fails on the pug command.
However, to use babel, the Typescript files first have to be compiled to javascript. Can anyone help me get out of this Catch-22?
The text was updated successfully, but these errors were encountered: