Skip to content

Commit

Permalink
Add docs for literals and enum keys in map (#1181)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->



> [!IMPORTANT]
> Add documentation for using enums and literal strings as keys in maps
in `types.mdx`.
> 
>   - **Documentation**:
> - Updated `types.mdx` to include examples of using enums and literal
strings as keys in maps.
> - Added syntax examples for `map<Category, string>` and `map<"A" | "B"
| "C", string>` in `types.mdx`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for 7174af0. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
antoniosarosi authored Nov 19, 2024
1 parent 39e0271 commit d0e462a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion fern/03-reference/baml/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,28 @@ A collection of elements of the same type.

### Map

A mapping of strings to elements of another type.
A mapping of strings or enums to elements of another type.

**Syntax**: `map<string, ValueType>`

**Example**: `map<string, string>`

Enums and literal strings can also be used as keys.

```baml
enum Category {
A
B
C
}
// Enum key syntax
map<Category, string>
// Literal strings syntax
map<"A" | "B" | "C", string>
```

{/* <Info>
For TS users: `map<string, ValueType>` will generate a
`Record<string, ValueType>` type annotation, but using any other type for the
Expand Down

0 comments on commit d0e462a

Please sign in to comment.