microsoft / microsoft/typespec

There is no way to constrain a parameter type to something that is spreadable. And union-of-objects is not spreadable.

Open
#1,566 2 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

Two related issues; there is no way to restrict `T` to something that is spreadable. Something like this:

```
model Something {
... T;
}

model ThisWorks is Something<{}>;

// model ThisWillBlowUpWithASquigglyInsideModelSomething is Something<{} | {}>;
```

passes the compiler until you try to pass in the union as a template parameter. The error will be on in an unfortunate location (at the point of spread) as opposed to the point of usage.

In an ideal world, spreading a union would somehow work (because it is challenging to write extensible libraries without disallowing union types). But at the very least, it would be good to have some way to say that a template argument has to be spreadable.

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.