-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(compiler): Bring back the Map<K, V>
type
#5573
base: main
Are you sure you want to change the base?
Changes from all commits
3ac724c
7abf3ee
d22db35
605e033
93a796a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: feature | ||
packages: | ||
- "@typespec/compiler" | ||
--- | ||
|
||
Bring back the `Map<K, V>` type to intrinsics |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,7 +280,7 @@ export type NeverIndexer = { | |
}; | ||
|
||
export type ModelIndexer = { | ||
readonly key: Scalar; | ||
readonly key: Enum | Scalar | Union; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this mean the key here could be an enum, or scalar or union of enums and/or scalars? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added Union here for inline enum-like types, such as Union of models won't be ok here, at least the key type must be assignable to string for Maps, by the Please let me know if there is a better approach! 🙏 I will add missing test cases for enums though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the union here actually means union of literals of enums and scalars. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. The compiler can check the key type for |
||
readonly value: Type; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing missing with Map is deciding on how to serialize it. Keeping it as a JS object only work if the key is a string or a number. So as much as it might unlock the number case it now opens up a wide range of things that cannot be represented without defining an alternate schema
For example as:
[K, V][]
{key: K, value: V}[]
So to bring back this type in I believe we'd need to figure how to define how a map is encoded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah Map<K,V> in js is not serializable therefore in TCGC we made an update to avoid of using Map<K,V> in its public APIs, because we have some emitters that need to transport the output of TCGC into another process written in their own language (such as .net, java and python)