microsoft / microsoft/typespec

Inconsistent template args behavior between model extends vs model is

Open
#6,699 0 comments 0 reactions 1 assignee Claimed by @chrisradek View on GitHub
bug compiler:core triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

[TypeSpec Playgound](https://typespec.io/playground/?c=bW9kZWwgTXlUZW1wbGF0ZTxCYXIgZXh0ZW5kcyBzdHJpbmcgfCBieXRlcz4gew0KICBmaWVsZDogQmFyOw0KfQ0KDQrIREXFN2VkyUDLV8ZLPiB7fTvKMUlzIGnUJjvKVlRlc3TGeC8vIFVuY29tbWVudCB0aGlzIG91dCBhbmQgaXQgZmFpbHMgYmVjYXVzZSBg5gCBZWRG5ACsYMRlYSDIZVBhcmFtZXRlci7HVs0tOusAyC7lAOs7xCdpc8keSXPJGH0%3D&e=%40typespec%2Fopenapi3&options=%7B%7D)

Take this example:
```tsp
model MyTemplate {
field: Bar;
}

model MyExtended extends MyTemplate {};
model MyIs is MyTemplate;

model Test {
// extendedField has type `TemplateParameter`
extendedField: MyExtended.field;
// isField has type `string`
isField: MyIs.field;
}
```

When assigning the `field` property from `MyExtended` or `MyIs` models to a property in `Test`, I expected the same results - that the type of the field is `string`. This is because in both of my models, I've passed in `string` as the template argument.

However, this is only the case when using `is`. I'm not sure if this was intentional but the behavior is surprising.

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.