microsoft / microsoft/TypeScript
No validation in JSX when using template string index signatures
オープン
@ahejlsberg がすでに取り組んでいます。
2021年6月29日 から。
In Discussion
Rescheduled
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Here's the shortest example:
import * as React from "react";
interface Props {
foo: string;
bar: number;
[dataProp: `data-${string}`]: string;
}
function Yadda(props: Props) {
return <div />;
}
let props: Props = {
foo: "",
bar: 0,
"data-yadda": 42,
};
let x = <Yadda foo="hello" bar={42} data-yadda={42} />;
Expected: TypeScript should error on data-yadda, just as if we had explicitly declared a data-yadda property in Props, or if we had used a string index signature.
Actual: JSX dashed properties are exempt from these checks on the target object if a corresponding property doesn't exist.
My expectation is that if an index signature exists, and a property should be covered by that index signature, then TypeScript should check that the property is compatible with that index signature.
Here's a longer example that could be used in tests.
import * as React from "react";
interface Props {
foo: string;
bar: number;
[dataProp: `data-${string}`]: string;
}
function Yadda(props: Props) {
return <div />;
}
// Errors as expected on data-yadda. ✅
let propsObj1: Props = {
foo: "",
bar: 0,
"data-yadda": 42,
};
// Should error on data-yadda, does not. ❌
let x = <Yadda foo="hello" bar={42} data-yadda={42} />;
/////////
let propsObj2 = {
foo: "",
bar: 0,
"data-yadda": 42,
};
// Should error on data-yadda, does not. ❌
let y = <Yadda {...propsObj2} />
// Errors as expected on data-yadda. ✅
propsObj1 = propsObj2;
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。