You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Extension of #9230 to support completions of tagged union types. When doing property access on a tagged union type, only the discriminator property is provided in completions because it exists in all union members. The completions need to be extended to support completions inside of scopes where an object of the union type has been discriminated/type-guarded.
Describe the solution you'd like
Take the following example where | represents where completions relevant to this issue would be provided:
typetypeA = {
type: 'a'value: string
}
typetypeB = {
type: 'b'value: int
}
@discriminator('type')
typeunionType = typeA | typeBparamunionParamunionTyperesourcer1'...' = {
name: '...'properties: {
prop: unionParam.type == 'a' ? unionParam.| : unionParam.| // first position: should be completions for type A. Second position: should be only a type completion or anything except 'a'.
}
}
resourcer2'...' = if (unionParam.type == 'a') {
name: '...'properties: {
prop: unionParam.|
}
}
In these cases, since unionParam is discriminated by the condition checks, a certain set of completions sourced from the union members could be provided.
If the type-guard is simple, such as checking if the discriminator property equals exactly one value, property completions for that specific union member could be provided.
If conditions are more complex, such as checking if the discriminator property is equal to 2 or more values, then property completions would need to either be limited to just the discriminator or limited to the overlap between all possible members where property types are the same. Including all completions across possible members will likely lead to confusion/error and conflict when completion items are generated, such as members having overlapping property names with different types. In general, completions should likely be limited to safe options.
If conditions include checks for discriminator property values but include other conditions that cannot be evaluated until deploy time, completions will need to be limited to safe property completions.
It may be useful to take a look at the existing TypeScript implementation for how completions are suggested in various type guarded scenarios.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Extension of #9230 to support completions of tagged union types. When doing property access on a tagged union type, only the discriminator property is provided in completions because it exists in all union members. The completions need to be extended to support completions inside of scopes where an object of the union type has been discriminated/type-guarded.
Describe the solution you'd like
Take the following example where
|
represents where completions relevant to this issue would be provided:In these cases, since
unionParam
is discriminated by the condition checks, a certain set of completions sourced from the union members could be provided.If the type-guard is simple, such as checking if the discriminator property equals exactly one value, property completions for that specific union member could be provided.
If conditions are more complex, such as checking if the discriminator property is equal to 2 or more values, then property completions would need to either be limited to just the discriminator or limited to the overlap between all possible members where property types are the same. Including all completions across possible members will likely lead to confusion/error and conflict when completion items are generated, such as members having overlapping property names with different types. In general, completions should likely be limited to safe options.
If conditions include checks for discriminator property values but include other conditions that cannot be evaluated until deploy time, completions will need to be limited to safe property completions.
It may be useful to take a look at the existing TypeScript implementation for how completions are suggested in various type guarded scenarios.
The text was updated successfully, but these errors were encountered: