提交 0631d3bf 编写于 作者: Q qiang

docs: uts object fn

上级 13c510e1
...@@ -11,7 +11,7 @@ UTS 语言支持使用对象字面量(Object Literal)声明类型,但不 ...@@ -11,7 +11,7 @@ UTS 语言支持使用对象字面量(Object Literal)声明类型,但不
```ts ```ts
type Person = { type Person = {
name: string name: string
printName: () => void fn: () => void
} }
function greet(person: Person) { function greet(person: Person) {
...@@ -22,7 +22,7 @@ function greet(person: Person) { ...@@ -22,7 +22,7 @@ function greet(person: Person) {
未支持的用法: 未支持的用法:
```ts ```ts
function greet(person: { name: string, printName: () => void }) { function greet(person: { name: string, fn: () => void }) {
// ... // ...
} }
``` ```
...@@ -34,13 +34,13 @@ function greet(person: { name: string, printName: () => void }) { ...@@ -34,13 +34,13 @@ function greet(person: { name: string, printName: () => void }) {
正确的用法: 正确的用法:
```ts ```ts
greet({ name: 'Tom', printName: function () { console.log(this.name) } } as Person) greet({ name: 'Tom', fn: function () { } } as Person)
``` ```
类型不匹配: 类型不匹配:
```ts ```ts
greet({ name: 'Tom', printName: function () { console.log(this.name) } }) greet({ name: 'Tom', fn: function () { } })
``` ```
## 嵌套限制 ## 嵌套限制
...@@ -136,7 +136,7 @@ UTS 语言虽然不支持匿名对象类型声明,但是支持匿名的对象 ...@@ -136,7 +136,7 @@ UTS 语言虽然不支持匿名对象类型声明,但是支持匿名的对象
```ts ```ts
const person: UTSJSONObject = { const person: UTSJSONObject = {
name: 'Tom', name: 'Tom',
printName: () => { fn: () => {
// ... // ...
} }
} }
......
...@@ -38,6 +38,6 @@ const p: Person = new P('Tom') ...@@ -38,6 +38,6 @@ const p: Person = new P('Tom')
```ts ```ts
type Person = { type Person = {
name: string name: string
printName: () => void fn: () => void
} }
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册