Skip to content

Commit

Permalink
Ensure types with any don't report as fragment refs
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Dec 9, 2024
1 parent 10c8755 commit 91d9823
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/masking/__benches__/types.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ test("MaybeMasked handles odd types", (prefix) => {

bench(prefix + "unknown instantiations", () => {
attest<unknown, MaybeMasked<unknown>>();
}).types([52, "instantiations"]);
}).types([54, "instantiations"]);
bench(prefix + "unknown functionality", () => {
expectTypeOf<MaybeMasked<unknown>>().toBeUnknown();
});
Expand Down Expand Up @@ -464,3 +464,19 @@ test("base type, multiple fragments on sub-types", (prefix) => {
}>();
});
});

test("does not detect `$fragmentRefs` if type contains `any`", (prefix) => {
interface Source {
foo: { bar: any[] };
}

bench(prefix + "instantiations", () => {
return {} as MaybeMasked<Source>;
}).types([6, "instantiations"]);

bench(prefix + "functionality", () => {
const x = {} as MaybeMasked<Source>;

expectTypeOf(x).branded.toEqualTypeOf<Source>();
});
});
3 changes: 2 additions & 1 deletion src/masking/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ export type RemoveFragmentName<T> =
T extends any ? Omit<T, " $fragmentName"> : T;

export type ContainsFragmentsRefs<TData> =
TData extends object ?
true extends IsAny<TData> ? false
: TData extends object ?
" $fragmentRefs" extends keyof TData ?
true
: ContainsFragmentsRefs<TData[keyof TData]>
Expand Down

0 comments on commit 91d9823

Please sign in to comment.