microsoft / microsoft/typespec

Decorators with named parameters?

Open
#513 4 comments 0 reactions 0 assignees View on GitHub
design:needed
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

Currently, it seems that decorators only accept arguments positionally. I'm wondering if it would be feasible/beneficial to support keyword arguments.

```
// 1 - Positional makes it hard to know the expected inputs when there are many options
@petDecorator("Fluffy", 10, "orange", "tuna")
...

// 2 - Makes it a lot easier to know what you are setting, and only set those parameters you care about.
@petDecorator(name: "Fluffy", age: 10, color: "orange", favoriteTreat: "tuna")
...

// 3 - Alternatively, you could just have many small decorators.
@petName("Fluffy") @petAge(10) @petColor("orange") @petFavoriteTreat("tuna")
...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.