Skip to content

fix: FilterVisibility now applies visibility filter to inherited types (extends)#11043

Draft
Copilot wants to merge 8 commits into
mainfrom
copilot/bug-fix-filter-visibility
Draft

fix: FilterVisibility now applies visibility filter to inherited types (extends)#11043
Copilot wants to merge 8 commits into
mainfrom
copilot/bug-fix-filter-visibility

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

FilterVisibility only filtered properties directly on a model but ignored baseModel, so inherited properties with incompatible visibility passed through unfiltered.

model Base {
  @visibility(Lifecycle.Read) id: string;
}

model User extends Base {
  name: string;
}

// Previously: UserCreate still inherited unfiltered Base with `id` visible
// Now: Base is also filtered, producing BaseCreate with `id` removed
model UserCreate is FilterVisibility<User, #{ all: #[Lifecycle.Create] }, "{name}Create">;

Changes

  • packages/compiler/src/lib/visibility.ts — In createVisibilityFilterMutator's Model.replace handler, recursively apply the visibility filter mutator to model.baseModel when present
  • packages/compiler/test/visibility.test.ts — Added test cases covering:
    • Multi-level inheritance where all base types have filtered properties
    • Base model unchanged when it has no visibility-restricted properties
    • Entire base chain unchanged when only the leaf has filtered properties
    • Intermediate types renamed when their deeper base is transformed
    • Direct applyVisibilityFilter API with inheritance
    • Self-referential model (e.g., next?: LinkedNode) does not produce infinite regress

…s (extends)

When filtering a model by visibility, the filter is now also applied to
base models in the inheritance chain. This ensures that properties with
incompatible visibility in base types are properly filtered out.

Closes #11036

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jun 22, 2026
Copilot AI changed the title [WIP] Fix FilterVisibility to honor extends fix: FilterVisibility now applies visibility filter to inherited types (extends) Jun 22, 2026
Copilot AI requested a review from markcowl June 22, 2026 18:41

@markcowl markcowl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot Please pull the latest from main, make the suggested changes, ensure all tests pass and all files are formatted correctly. Ensure that only changes associated with this PR are in the pr diff

Comment thread packages/compiler/test/visibility.test.ts
Copilot AI and others added 2 commits June 22, 2026 20:46
…r-visibility

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please pull the latest from main, make the suggested changes, ensure all tests pass and all files are formatted correctly. Ensure that only changes associated with this PR are in the pr diff

Done — merged latest from main, added the self-referential model test, verified all 61 visibility tests pass, and confirmed formatting is correct. The diff only contains the 3 expected files.

Copilot AI requested a review from markcowl June 22, 2026 20:53

@markcowl markcowl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot Please pull the latest from main, make the suggested update, ensure all tests pass, all files are correctly formatted, and only the changes associated with thios PR are in the pr diff

Comment thread packages/compiler/test/visibility.test.ts
Copilot AI and others added 2 commits June 22, 2026 23:05
…r-visibility

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please pull the latest from main, make the suggested update, ensure all tests pass, all files are correctly formatted, and only the changes associated with thios PR are in the pr diff

Done — merged latest main, updated the self-referential test so the target model extends a base with a self-link property, all 61 visibility tests pass, formatting is correct, and the diff contains only the 3 expected files.

Copilot AI requested a review from markcowl June 22, 2026 23:08
@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11043

commit: 1e6c9a4

@markcowl

Copy link
Copy Markdown
Contributor

@copilot, the lint check is failing. You can see the results here: https://github.com/microsoft/typespec/actions/runs/27990186877/job/82845301849?pr=11043 or run pnpm lint to see them.

Please pull the latest from main, fix the issue, ensure that all files are correctly formatted and only the changes associated with this pr are in the pr diff.

Copilot AI and others added 2 commits June 30, 2026 02:47
…r-visibility

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, the lint check is failing. You can see the results here: https://github.com/microsoft/typespec/actions/runs/27990186877/job/82845301849?pr=11043 or run pnpm lint to see the...

Fixed — removed 4 unused program destructurings that caused @typescript-eslint/no-unused-vars warnings. Merged latest from main, all tests pass, lint is clean, and the diff contains only the 3 expected files. Commit: a4eed9b.

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.

2 participants