Skip to content

Commit

Permalink
docs: add index signature alias self reference in the schema
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 2, 2023
1 parent 2ced230 commit 7d90112
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 3 deletions.
39 changes: 39 additions & 0 deletions docs/reference/lang/tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,45 @@ schema Person:
[...str]: str # Except for the `name` and `age` attributes, the key type of all other attributes of the schema must be `str`, and the value type must also be `str`.
```

- Define the index signature attribute alias and use it in its default value.

```python
schema Environment:
[id: str]: EnvironmentSpec = {
fullName = id
}

schema EnvironmentSpec:
fullName: str
shortName: str = fullName
accountID: int

environment = Environment {
development: {
shortName: "dev"
accountID: 123456
}
production: {
shortName: "prod"
accountID: 456789
}
}
```

The output is

```yaml
environment:
production:
fullName: production
shortName: prod
accountID: 456789
development:
fullName: development
shortName: dev
accountID: 123456
```
- Define the index signature attribute alias and use it with the check block.
```python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,46 @@ schema Person:

###### 定义索引签名别名

可以为索引签名定义类型注解的属性别名,并将其与检查块一起使用。
- 可以为索引签名定义类型注解的属性别名,并将其与索引签名的默认值一起使用。

```python
schema Environment:
[id: str]: EnvironmentSpec = {
fullName = id
}

schema EnvironmentSpec:
fullName: str
shortName: str = fullName
accountID: int

environment = Environment {
development: {
shortName: "dev"
accountID: 123456
}
production: {
shortName: "prod"
accountID: 456789
}
}
```

YAML 输出为:

```yaml
environment:
production:
fullName: production
shortName: prod
accountID: 456789
development:
fullName: development
shortName: dev
accountID: 123456
```
- 可以为索引签名定义类型注解的属性别名,并将其与检查块一起使用。
```python
schema Data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,46 @@ schema Person:

###### 定义索引签名别名

可以为索引签名定义类型注解的属性别名,并将其与检查块一起使用。
- 可以为索引签名定义类型注解的属性别名,并将其与索引签名的默认值一起使用。

```python
schema Environment:
[id: str]: EnvironmentSpec = {
fullName = id
}

schema EnvironmentSpec:
fullName: str
shortName: str = fullName
accountID: int

environment = Environment {
development: {
shortName: "dev"
accountID: 123456
}
production: {
shortName: "prod"
accountID: 456789
}
}
```

YAML 输出为:

```yaml
environment:
production:
fullName: production
shortName: prod
accountID: 456789
development:
fullName: development
shortName: dev
accountID: 123456
```
- 可以为索引签名定义类型注解的属性别名,并将其与检查块一起使用。
```python
schema Data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,46 @@ schema Person:

###### 定义索引签名别名

可以为索引签名定义类型注解的属性别名,并将其与检查块一起使用。
- 可以为索引签名定义类型注解的属性别名,并将其与索引签名的默认值一起使用。

```python
schema Environment:
[id: str]: EnvironmentSpec = {
fullName = id
}

schema EnvironmentSpec:
fullName: str
shortName: str = fullName
accountID: int

environment = Environment {
development: {
shortName: "dev"
accountID: 123456
}
production: {
shortName: "prod"
accountID: 456789
}
}
```

YAML 输出为:

```yaml
environment:
production:
fullName: production
shortName: prod
accountID: 456789
development:
fullName: development
shortName: dev
accountID: 123456
```
- 可以为索引签名定义类型注解的属性别名,并将其与检查块一起使用。
```python
schema Data:
Expand Down
39 changes: 39 additions & 0 deletions versioned_docs/version-0.6.0/reference/lang/tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,45 @@ schema Person:
[...str]: str # Except for the `name` and `age` attributes, the key type of all other attributes of the schema must be `str`, and the value type must also be `str`.
```

- Define the index signature attribute alias and use it in its default value.

```python
schema Environment:
[id: str]: EnvironmentSpec = {
fullName = id
}

schema EnvironmentSpec:
fullName: str
shortName: str = fullName
accountID: int

environment = Environment {
development: {
shortName: "dev"
accountID: 123456
}
production: {
shortName: "prod"
accountID: 456789
}
}
```

The output is

```yaml
environment:
production:
fullName: production
shortName: prod
accountID: 456789
development:
fullName: development
shortName: dev
accountID: 123456
```
- Define the index signature attribute alias and use it with the check block.
```python
Expand Down
39 changes: 39 additions & 0 deletions versioned_docs/version-0.7.0/reference/lang/tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,45 @@ schema Person:
[...str]: str # Except for the `name` and `age` attributes, the key type of all other attributes of the schema must be `str`, and the value type must also be `str`.
```

- Define the index signature attribute alias and use it in its default value.

```python
schema Environment:
[id: str]: EnvironmentSpec = {
fullName = id
}

schema EnvironmentSpec:
fullName: str
shortName: str = fullName
accountID: int

environment = Environment {
development: {
shortName: "dev"
accountID: 123456
}
production: {
shortName: "prod"
accountID: 456789
}
}
```

The output is

```yaml
environment:
production:
fullName: production
shortName: prod
accountID: 456789
development:
fullName: development
shortName: dev
accountID: 123456
```
- Define the index signature attribute alias and use it with the check block.
```python
Expand Down

0 comments on commit 7d90112

Please sign in to comment.