Skip to content

Add typekit to list types under a container (namespace/interface) #7391

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

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

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 19, 2025

This PR adds a new utility function to the typekit that allows listing all types under a container (namespace or interface) that match a specific filter criteria.

The new function is implemented as:

$.type.listUnder(container, (type) => filter)

This utility provides a consistent way to list types under a namespace or interface and apply a filter to find types with specific characteristics, which is a common need in libraries consuming TypeSpec types.

Example usage

// List all models in a namespace
const models = typespecType.listUnder(
  namespace, 
  (type): type is Model => type.kind === "Model"
);

// List all types with a specific decorator
const withMyDec = typespecType.listUnder(
  namespace, 
  (type) => type.decorators.some(d => d.decorator.name === "@myDec")
);

// List operations from a specific namespace with non-recursive search
const operations = typespecType.listUnder(
  namespace,
  (type) => type.kind === "Operation",
  { recursive: false }
);

The implementation is based on the pattern used by listOperationsIn helper, but generalized to work with any type category.

Fixes #7367.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.fwupd.org
    • Triggering command: /usr/bin/fwupdmgr refresh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@microsoft-github-policy-service microsoft-github-policy-service bot added compiler:core Issues for @typespec/compiler compiler:emitter-framework Issues for the emitter framework ide Issues for VS, VSCode, Monaco, etc. lib:http lib:openapi lib:rest lib:versioning lib:http-specs For issues/prs related to the @typespec/http-specs package meta:blog Blog updates meta:website TypeSpec.io updates tspd Issues for the tspd tool emitter:client:all General issue for client emitters emitter:client:js Issue for the JS client emitter: @typespec/http-client-js emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp emitter:client:java Issue for the Java client emitter: @typespec/http-client-java emitter:client:python Issue for the Python client emitter: @typespec/http-client-python emitter:graphql Issues for @typespec/graphql emitter emitter:json-schema emitter:protobuf The protobuf emitter emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter emitter:service:csharp labels May 19, 2025
@timotheeguerin timotheeguerin removed meta:blog Blog updates tspd Issues for the tspd tool compiler:emitter-framework Issues for the emitter framework emitter:service:csharp emitter:service:js lib:versioning lib:http lib:openapi lib:rest emitter:openapi3 Issues for @typespec/openapi3 emitter openapi3:converter Issues for @typespec/openapi3 openapi to typespec converter ui:playground ui:type-graph-viewer emitter:client:java Issue for the Java client emitter: @typespec/http-client-java emitter:client:python Issue for the Python client emitter: @typespec/http-client-python emitter:service:java Issue for Java service emitter emitter:graphql Issues for @typespec/graphql emitter spector Issues related to spector and the spec sets lib:http-specs For issues/prs related to the @typespec/http-specs package emitter:client:all General issue for client emitters emitter:client:js Issue for the JS client emitter: @typespec/http-client-js labels May 19, 2025
Copilot finished work on behalf of timotheeguerin May 19, 2025 18:02
Copy link
Member

Choose a reason for hiding this comment

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

this file is also in the wrong location

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the type-utils.test.ts file to the correct location in the test directory and updated imports in 9a633f8.

Copy link
Member

Choose a reason for hiding this comment

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

this should be added to packages/compiler/test/typekit/type.test.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved the test file to packages/compiler/test/typekit/type.test.ts in b4d3801.

Copilot finished work on behalf of timotheeguerin May 19, 2025 18:45
Copilot finished work on behalf of timotheeguerin May 19, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:core Issues for @typespec/compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add typekit to allow listsing all types under a container (namespace/interface)
2 participants