Skip to content

Commit

Permalink
fix: casing of mapType values and add example link
Browse files Browse the repository at this point in the history
  • Loading branch information
akkshitgupta committed Jan 28, 2024
1 parent 14d8186 commit 6de13b6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions docs/languages/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@ Check out this [example out for a live demonstration](../../examples/typescript-

Typescript offers different `mapType`s which can simplify the use based on the needs. This behavior can be changed through the [`mapType` configuration](https://github.com/asyncapi/modelina/blob/master/docs/generators.md#typescript).

- Use `Map` when you need a dynamic collection of key-value pairs with built-in methods for manipulation.
- Use `Record` when you want to define an object with specific keys and their corresponding value types.
- Use `IndexedObject` (or an interface with index signature) for a more generic approach when working with objects with dynamic keys.
- Use `map` when you need a dynamic collection of key-value pairs with built-in methods for manipulation.
- Use `record` when you want to define an object with specific keys and their corresponding value types.
- Use `indexedObject` (or an interface with index signature) for a more generic approach when working with objects with dynamic keys.

An example of the generated code can be seen below:

```ts
// mapType = indexedObject
private _person?: { [name: string]: any };

// mapType = Map
// mapType = map
private _person?: Map<string, any>;

// mapType = Record
// mapType = record
private _person?: Record<string, any>;
```

Also, check out this [example for a live demonstration](../../examples/typescript-change-map-type).

## Generate union types instead of enums

Typescript offers union types which can simplify the use as no keywords are needed and the values can be set directly. This behavior can be changed through the [modelType configuration](https://github.com/asyncapi/modelina/blob/master/docs/generators.md#typescript). An example of the generated code can be seen below:
Expand Down

0 comments on commit 6de13b6

Please sign in to comment.