microsoft / microsoft/typespec

Allow defaults for declarations

Open
#2,359 5 comments 2 reactions 0 assignees View on GitHub
compiler:core design:accepted triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

It would be nice to allow specifying defaults on a declaration. For example, something like:

```
@default(10)
scalar rating extends int8;
// or
scalar rating extends int8 = 10;

declare x = { a: string } = #{ a: "hi" };

@default(#{ x: 0, y: 0 })
model Point {
x: float64;
y: float64;
} = #{ x: 0, y: 0 };
```

Otherwise you have to make sure to apply this default everywhere `rating` is used, or create an anonymous model to spread in. Neither are particularly palatable.

Object defaults probably depend on the `#` syntax, and the sketched `default` decorator has similar dependencies to #514.

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.