这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@alina-zaieva
Copy link

Please fill in this template.

If changing an existing definition:

@alina-zaieva alina-zaieva requested a review from alloy as a code owner November 7, 2025 09:09
@typescript-bot
Copy link
Contributor

typescript-bot commented Nov 7, 2025

@alina-zaieva Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.

This is a live comment that I will keep updated.

1 package in this PR

Code Reviews

Because you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • 🕐 Most recent commit is approved by type definition owners or DT maintainers

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.

Inactive

This PR has been inactive for 8 days.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 74036,
  "author": "alina-zaieva",
  "headCommitOid": "80daff6b697975893ecf86257822f86371b80f5b",
  "mergeBaseOid": "2243b87255f228f1052ba457c4eaed37dce55047",
  "lastPushDate": "2025-11-07T09:09:44.000Z",
  "lastActivityDate": "2025-11-12T21:53:09.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": true,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Popular",
  "pkgInfo": [
    {
      "name": "relay-runtime",
      "kind": "edit",
      "files": [
        {
          "path": "types/relay-runtime/experimental.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/relay-runtime/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/relay-runtime/lib/store/live-resolvers/resolverDataInjector.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/relay-runtime/package.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/relay-runtime/relay-runtime-tests.tsx",
          "kind": "test"
        }
      ],
      "owners": [
        "captbaritone",
        "alloy",
        "maraisr",
        "morrys",
        "levibuzolic"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Popular"
    }
  ],
  "reviews": [
    {
      "type": "stale",
      "reviewer": "alloy",
      "date": "2025-11-12T21:41:12.000Z",
      "abbrOid": "aac2b8b"
    }
  ],
  "mainBotCommentID": 3501411554,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added the Popular package This PR affects a popular package (as counted by NPM download counts). label Nov 7, 2025
@typescript-bot typescript-bot moved this to Waiting for Code Reviews in Pull Request Status Board Nov 7, 2025
@typescript-bot
Copy link
Contributor

🔔 @captbaritone @alloy @maraisr @morrys @levibuzolic — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

// The type returned by fields annotated with `@catch`
export type Result<T, Error> = OkayResult<T> | ErrorResult<Error>;

export function isValueResult<T = unknown>(input: Result<T, Error>): input is OkayResult<T>;
Copy link
Author

Choose a reason for hiding this comment

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

The type definition here and for isErrorResult is a bit strange in the upstream since Error generic type argument is always Error type. Not sure if that is intentional or an accident, but I've replicated the same here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It shouldn't matter for OkayResult, as it doesn't contain any errors, but for ErrorResult it seems like ErrorResult would lose precision and always use the Error supertype. This might be a Flow difference, which you can try on their playground.

For our needs I think we should declare the error type and perhaps even rename it (to E) to avoid confusion. So this test IMO should pass:

class CustomError < Error {}
const input: ErrorResult<CustomError> = { ok: false, errors: [new CustomError()] };
if (isErrorResult(input)) {
  const e: CustomError = input.errors[0]!;
}

Copy link
Author

Choose a reason for hiding this comment

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

Confirmed in Flow playground that the behavior there matches what we have here in TypeScript - both isValueResult and isErrorResult can only accept Result values where the error is Error instance. To me this looks like a bug in Relay, but since the runtime behavior would be the same, yes, I can fix the TS typings at least 🙂

Copy link
Author

Choose a reason for hiding this comment

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

@alloy done, isErrorResult now mirrors isValueResult and the type argument is now E instead of Error to make it clear that this is a type argument.

// The type returned by fields annotated with `@catch`
export type Result<T, Error> = OkayResult<T> | ErrorResult<Error>;

export function isValueResult<T = unknown>(input: Result<T, Error>): input is OkayResult<T>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It shouldn't matter for OkayResult, as it doesn't contain any errors, but for ErrorResult it seems like ErrorResult would lose precision and always use the Error supertype. This might be a Flow difference, which you can try on their playground.

For our needs I think we should declare the error type and perhaps even rename it (to E) to avoid confusion. So this test IMO should pass:

class CustomError < Error {}
const input: ErrorResult<CustomError> = { ok: false, errors: [new CustomError()] };
if (isErrorResult(input)) {
  const e: CustomError = input.errors[0]!;
}

Co-authored-by: Eloy Durán <eloy.de.enige@gmail.com>
@typescript-bot
Copy link
Contributor

@alloy Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Popular package This PR affects a popular package (as counted by NPM download counts).

Projects

Status: Waiting for Code Reviews

Development

Successfully merging this pull request may close these issues.

3 participants