Skip to content

Commit

Permalink
带有命名空间的 JSX 属性
Browse files Browse the repository at this point in the history
5.1
  • Loading branch information
zhongsp committed Jul 2, 2023
1 parent 76b0abd commit 616079c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions zh/release-notes/typescript-5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,39 @@ namespace JSX {
```

感谢 [Sebastian Silbermann](https://github.com/eps1lon)[PR](https://github.com/microsoft/TypeScript/pull/51328)

## 带有命名空间的 JSX 属性

TypeScript 支持在 JSX 里使用带有命名空间的属性。

```tsx
import * as React from "react";

// Both of these are equivalent:
const x = <Foo a:b="hello" />;
const y = <Foo a : b="hello" />;

interface FooProps {
"a:b": string;
}

function Foo(props: FooProps) {
return <div>{props["a:b"]}</div>;
}
```

当名字的第一段是小写名称时,在 `JSX.IntrinsicAttributes` 上查找带命名空间的标记名是类似的。

```tsx
// In some library's code or in an augmentation of that library:
namespace JSX {
interface IntrinsicElements {
["a:b"]: { prop: string };
}
}

// In our code:
let x = <a:b prop="hello!" />;
```

感谢 [Oleksandr Tarasiuk](https://github.com/a-tarasyuk)[PR](https://github.com/microsoft/TypeScript/pull/53799)

0 comments on commit 616079c

Please sign in to comment.