# JSX

## 1. 类型断言

两种类型断言

```
1. 
var foo = <foo>bar  

2. 

var foo = bar as foo;
```

由于 `jsx` 语法的原因，只能使用 `as` 操作符

## 2. 类型检查

对于原生dom标签，如 div， span 总是小写字母开头。 对于自定义组件都是大写字母开头

## 3. 固有元素(dom标签)

如果你想在JSX中使用  ，通常是会报错的，因为foo不是dom标签，通常是不会出现在 `JSX.IntrinsicElements`接口中的，如果要能够支持 foo ，则必须扩展该接口：

```javascript
declare namespace JSX {
    interface IntrinsicElements {
        foo: any  // 扩展
    }
}

<foo />; // 正确
<bar />; // 错误

也可以使用以下代码，全部通过

declare namespace JSX {
    interface IntrinsicElements {
        [elemName: string]: any;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yes-1-am.gitbook.io/blog/typescript-yu-fa/jsx.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
