Skip to content
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

Allow referencing items from a template parameter #2101

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

timotheeguerin
Copy link
Member

@timotheeguerin timotheeguerin commented Jun 21, 2023

fix #1280
Revisit #1543

This is quite key to making option bag for template a reality.

alias Options = {
  name: string;
  value: string;
};
model Foo<T extends Options> {
  t: T.name;
}

Limitations: You have to use an alias. Cannot do it inline.

Todo:

  • tests

@github-actions
Copy link
Contributor

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2101/

Website: https://cadlwebsite.z1.web.core.windows.net/prs/2101/

constraint.kind === SyntaxKind.TypeReference ||
constraint.kind === SyntaxKind.Identifier)
) {
base = resolveTypeReferenceSym(constraint, mapper, resolveDecorator);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now when we resolve a template declaration type (uninstantiated) and you reference a template parameter with constrain the reference remains the template parameter but with this it would become the type in the constraint.

alias Options = {name: string};

model Foo<T extends Options> {
  n: T.name; // This resolve to `Scalar: string`
  t: T;            // This resolve to `TemplateParameter: T`
}

Wondering if then we need a new Type TemplateParameterMember or something like that to represent that accurately and not loose information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Referencing property of template parameter that extends something that has said property fails
1 participant