Skip to content

Commit 88935c5

Browse files
feat(groq): this attribute
1 parent ed333e6 commit 88935c5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/groq/src/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ describe("groq", () => {
6969
>().toStrictEqual<typeof UNIQUE_VALUE>();
7070
});
7171

72+
it("key", () => {
73+
const UNIQUE_VALUE: unique symbol = Symbol("");
74+
75+
expectType<
76+
ExecuteQuery<"key", Scope<any, { key: typeof UNIQUE_VALUE }, any>>
77+
>().toStrictEqual<typeof UNIQUE_VALUE>();
78+
});
79+
7280
it("*", () =>
7381
expectType<
7482
ExecuteQuery<

packages/groq/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,21 @@ type This<
143143
: never
144144
: never;
145145

146+
/**
147+
* @link https://sanity-io.github.io/GROQ/GROQ-1.revision1/#ThisAttribute
148+
*/
149+
type ThisAttribute<
150+
TExpression extends string,
151+
TScope extends Scope<any, any, any>
152+
> = TScope extends Scope<any, infer Value, any>
153+
? TExpression extends keyof Value
154+
? Value[TExpression]
155+
: never
156+
: never;
157+
146158
/**
147159
* @link https://sanity-io.github.io/GROQ/GROQ-1.revision1/#SimpleExpression
148160
*
149-
* @todo ThisAttribute
150161
* @todo FuncCall
151162
*/
152163
type SimpleExpression<
@@ -155,7 +166,8 @@ type SimpleExpression<
155166
> =
156167
| Everything<TExpression, TScope>
157168
| Parent<TExpression, TScope>
158-
| This<TExpression, TScope>;
169+
| This<TExpression, TScope>
170+
| ThisAttribute<TExpression, TScope>;
159171

160172
/**
161173
* @link https://sanity-io.github.io/GROQ/GROQ-1.revision1/#Parenthesis

0 commit comments

Comments
 (0)