-
Notifications
You must be signed in to change notification settings - Fork 887
Support for .tsx files #490
Comments
JSX support is coming in TS 1.6, and we plan to support it by the time that releases. Right now tslint depends on typescript We do have intentions of more closely following the latest TS syntax & language services API on our master branch (see #474), so look out for that soon! |
Thanks. Just from curiosity, how big is the change to make tslint work for tsx files but without any JSX linting support (let's suppose i will disable linting for JSX part of file)? Or to rephrase, I would like to tslint file regardless its extension. |
I think it's fairly trivial. tslint rules only walk certain nodes in the syntax tree, so when the TS language services get updated to include JSX syntax nodes, tslint will simply ignore them. |
@pepaar you can also consider using block comments to disable tslint for all the JSX code blocks until we get first-class support (which should be pretty soon) |
Here is my example: I have export default class GroupPerson {
/** Id */
id: string;
/** DisplayName */
displayName: string;
} Then if i run: If the file with same content has different extension, e.g.
Do you know what's the issue here? |
@pepaar Importing .tsx files is not going to work with any current version of tslint. The compiler is bundled with the tslint binary, so you're locked to that compiler version. You could build a version of tslint yourself that is able to import .tsx files by adding the compiler option Your best bet is to wait until we are tracking the TypeScript master branch in our repo (#474). |
Just released |
@adidahiya - this is great thanks. Consider the following: /// <reference path="../../tsd.d.ts" />
import * as React from "react";
interface IProps {
foo: string;
}
class MyComponent extends React.Component<IProps, {}> {
render(): JSX.Element {
return <span>{ this.props.foo }</span>;
}
}
export function BuildMyComponent(): JSX.Element {
let x: string = "test";
return <MyComponent foo={ x } />;
} I get the following whitespace warning:
Line 17 is the return statement in the exported function. My gut tells me that Thoughts? |
That looks like a bug. I tried to make the whitespace rule skip jsx elements for this exact reason. Looks like I missed some cases. |
Great, nice work! I found issue with noUnusedVariableRule: My app.tsx file:
Tslint error:
And root cause is at the line 160 in noUnusedVariableRule.js which returns undefined for next statement:
Also interesting thing is if you change the line in app.tsx from:
to
The error is not present anymore. Also, error is not present if I remove "private" from alertMe() definition. |
Addresses #490 and other user confusion a bit, I hope.
Addresses #490 and other user confusion a bit, I hope.
Typescipt now support JSX and it introduced .tsx extension for files containing JSX syntax. microsoft/TypeScript#3203
Do you plan to support .tsx files?
The text was updated successfully, but these errors were encountered: