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

Satisfies type assertion for typescript break with useImportTypeSyntax: true #4818

Open
PatrykWalach opened this issue Oct 11, 2024 · 2 comments

Comments

@PatrykWalach
Copy link

This is a file generated in my project with, relay 18.1.0 and "useImportTypeSyntax": true in relay.config.json

// MediaCover_media.graphql.ts
import type { ReaderFragment } from 'relay-runtime';
import type { FragmentRefs } from "relay-runtime";
import type { src as mediaCoverImageSrcResolverType } from "../lib/media/src";
// Type assertion validating that `mediaCoverImageSrcResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(mediaCoverImageSrcResolverType satisfies (
  rootKey: src_mediaCover$key,
  args: {
    extraLarge: boolean | null | undefined;
    large: boolean | null | undefined;
  },
) => string | null | undefined);

This code leads to runtime error
ReferenceError: mediaCoverImageSrcResolverType is not defined

It happens because (mediaCoverImageSrcResolverType satisfies ... is transpiled to mediaCoverImageSrcResolverType by typescript
but import type { src as mediaCoverImageSrcResolverType } from "../lib/media/src"; gets dropped at runtime

It's not possible to use satisfies between two types, only a value and a type.

The solution is to make this import without type keyword

import type { src as mediaCoverImageSrcResolverType } from "../lib/media/src";

Related to: #4797 #4772

@captbaritone
Copy link
Contributor

Thanks for the report. cc @drewatk

@alloy
Copy link
Contributor

alloy commented Oct 22, 2024

This bug is expected to be looked at in about 2 weeks.

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

3 participants