microsoft / microsoft/TypeScript
Suggest renaming file from .ts to .tsx if needed?
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
Search Terms
ts tsx react jsx rename file errors
Suggestion
When adding JSX elements (React) to a .ts file rather than a .tsx file, error messages aren't clear that it should be a .tsx file. If it's clear the user is intending to write JSX code, such as having multiple JSX-like components and/or components that extend React.Component, can a code fix be given (on the file? on individual <>-related parsing errors?) to rename to .tsx?
Use Cases
There's been some buzz on Twitter lately about how easy it is to forget to rename to .tsx. Some users are apparently even used to writing JSX in .js, so the need to use .tsx is a bit confusing for them.
Examples
Given this file.ts:
import * as React from "react";
export class ComponentClass extends React.Component {
public render() {
return <span />;
// index.ts(5,22): error TS1005: '>' expected.
// index.ts(5,23): error TS1161: Unterminated regular expression literal.
}
}
export const ComponentArrow = () => <span />;
// index.ts(11,43): error TS1005: '>' expected.
// index.ts(11,44): error TS1161: Unterminated regular expression literal.
Would it be possible to special-case just from these errors to suggest to rename the file? Alternately, if we just have the ComponentArrow errors, would it still be possible to suggest to rename the file?
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从包含 JSX 和 React.Component 的 .ts 示例中重现已报告的 TS1005 和 TS1161 诊断,然后将其行为与 .tsx 文件进行比较。确定 TypeScript 在哪里处理这些解析错误和文件重命名代码修复;对于所描述的情况出现合适的建议,并且两个示例都得到覆盖,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react, typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100