Skip to content
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

TS 『禁止不必要的类型约束』规则,可能影响 tsx 文件下正常使用 #65

Open
FlyingFatPenguin opened this issue Dec 6, 2022 · 1 comment

Comments

@FlyingFatPenguin
Copy link

tsx 文件中,尖括号含义可能出现歧义,即 ts 下的泛型与 html 中的标签。这种语法的二义性可能导致不合理的报错。
例如,在 tsx 文件中,定义一个带有一个泛型参数的箭头函数。VS Code 就会将 <T> 理解为标签,导致后续代码报错

const f = <T>(v: T) => v;

<T extends any> 是消除标签-泛型歧义的常用手段,但是会与目前规则冲突。

@otakustay
Copy link
Member

在实践中,建议无明确箭头函数语义的时候,用function f<T>即可,有明确需要箭头函数时,其实可以单独声明类型type F<T>

除此以外的情况,少量场合下使用注释禁掉规则更合适

建议在PR上直接评论,回头整理的时候不见得还刻是看issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants