microsoft / microsoft/typespec

[http-server-js] Add synthetic interface duplication handling

Open
#6,860 0 comments 0 reactions 1 assignee Claimed by @witemple-msft View on GitHub
emitter:service:js feature triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

Take the following example where a service contains multiple interfaces that each have an operation with the same name:
```tsp
import "@typespec/http";
using Http;

@service
namespace Service;

@route("/foo")
interface Foo {
get(): {
@body body: {
field: string;
};
};
}

@route("/bar")
interface Bar {
get(): {
@body body: {
field: boolean;
};
};
}
```
The responses/response bodies are anonymous model expressions. The htt-server-js emitter will attempt to generate TypeScript interfaces for these, but the interface name isn't taken into account. This results in interface names that are duplicated:

```ts
export interface GetResult {
body: Body;
}

export interface Body {
field: string;
}

export interface GetResult {
body: Body;
}

export interface Body {
field: boolean; // <-- Error because other `Body` interface has type `string`
}
```
There should be some way to handle duplicate synthetic types.

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.