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

Unsupported expression type: MemberExpression - Typegen failing on queries that use an object or enum in string interpolation #8293

Open
Jamiewarb opened this issue Jan 16, 2025 · 1 comment

Comments

@Jamiewarb
Copy link

Jamiewarb commented Jan 16, 2025

Describe the bug

When generating types using npx sanity typegen generate, generation will fail for queries that access an object or enum via string interpolation.

It fails with error Unsupported expression type: MemberExpression in file.ts:5:60 in "file.ts"

To Reproduce

  1. Add the following code to a project with type generation:
const enum DOCUMENT_ENUM {
  PAGE = 'page',
}
const DOCUMENT_OBJ = {
  PAGE: 'page',
} as const;

const someQuery = defineQuery(`*[_type == "${DOCUMENT_ENUM.PAGE}"]`);
const someQuery2 = defineQuery(`*[_type == "${DOCUMENT_OBJ.PAGE}"]`);
  1. Run npx sanity typegen generation

  2. Observe the error: Unsupported expression type: MemberExpression in file.ts:5:55 in "file.ts"

Note that it works as expected with a variable, such as:

const PAGE = 'page';
const someQuery = defineQuery(`*[_type == "${PAGE}"]`);

Expected behavior

The types are generated with correct string interpolation—in this case _type == "page"

Screenshots

Image

Which versions of Sanity are you using?

❯ npx sanity versions
@sanity/cli (global)          3.69.0 (latest: 3.70.0)
@sanity/code-input             5.1.2 (up to date)
@sanity/eslint-config-studio   5.0.1 (up to date)
@sanity/icons                  3.5.7 (up to date)
@sanity/image-url              1.1.0 (up to date)
@sanity/presentation          1.21.3 (up to date)
@sanity/types                 3.69.0 (latest: 3.70.0)
@sanity/ui                    2.11.2 (up to date)
@sanity/vision                3.69.0 (latest: 3.70.0)
sanity                        3.69.0 (latest: 3.70.0)

What operating system are you using?

MacOS Sonoma 14.6.1 (23G93)

Which versions of Node.js / npm are you running?

❯ npm -v && node -v
10.8.2
v20.17.0
@Jamiewarb Jamiewarb changed the title Typegen failing on queries that use an object or enum in string interpolation Unsupported expression type: MemberExpression - Typegen failing on queries that use an object or enum in string interpolation Jan 16, 2025
@Jamiewarb
Copy link
Author

I believe this is the same issue causing #7418 and is mentioned in the workaround of #6365

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

No branches or pull requests

1 participant