Skip to content

Conversation

@ericanderson
Copy link
Contributor

@ericanderson ericanderson commented Mar 22, 2023

Updates to reflect concern brought up by @gaearon in #64772 regarding this tweet.

Specifically:

  • All refs are now mutable as they always have technically been.
  • RefObject is now deprecated.
  • Components that took a ref previously only allowed ref variants that looked like { current: T | null } | { current: T } and they now accept variants that are like { current: T | undefined }.

@typescript-bot
Copy link
Contributor

typescript-bot commented Mar 22, 2023

@ericanderson Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

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

Status

  • ✅ No merge conflicts
  • ❌ Continuous integration tests have failed
  • 🕐 Most recent commit is approved by a DT maintainer

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 31 days — it is considered abandoned, and therefore closed!


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 64855,
  "author": "ericanderson",
  "headCommitOid": "7f33356aa39c21ddbb33f66a3de9f9079da1f1a9",
  "mergeBaseOid": "1d9d491c90bd1c852dea2a9ff36a7cf0bf48cd7c",
  "lastPushDate": "2023-03-22T18:18:39.000Z",
  "lastActivityDate": "2023-03-28T13:05:53.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "react",
      "kind": "edit",
      "files": [
        {
          "path": "types/react/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/test/hooks.tsx",
          "kind": "test"
        }
      ],
      "owners": [
        "johnnyreilly",
        "bbenezech",
        "pzavolinsky",
        "ericanderson",
        "DovydasNavickas",
        "theruther4d",
        "guilhermehubner",
        "ferdaber",
        "jrakotoharisoa",
        "pascaloliv",
        "hotell",
        "franklixuefei",
        "Jessidhia",
        "saranshkataria",
        "lukyth",
        "eps1lon",
        "zieka",
        "dancerphil",
        "dimitropoulos",
        "disjukr",
        "vhfmag",
        "hellatan",
        "priyanshurav",
        "Semigradsky"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [],
  "mainBotCommentID": 1480068687,
  "ciResult": "fail",
  "ciUrl": "https://github.com/DefinitelyTyped/DefinitelyTyped/commit/7f33356aa39c21ddbb33f66a3de9f9079da1f1a9/checks?check_suite_id=11740599047"
}

@typescript-bot typescript-bot added Critical package Author is Owner The author of this PR is a listed owner of the package. labels Mar 22, 2023
@typescript-bot
Copy link
Contributor

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Mar 22, 2023
@typescript-bot
Copy link
Contributor

@ericanderson The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@ericanderson
Copy link
Contributor Author

I missed an edge case that isn't quite acceptable that I am still trying to work through.

readonly current: T | null;
}
/**
* @deprecated All refs are mutable. This type has always been wrong. Expect it to change to
Copy link
Collaborator

Choose a reason for hiding this comment

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

This wording doesn't really add value. There was a rationale why we did this. It's like saying ReadonlyArray<SomeArray> "was always wrong". Just because something works in JavaScript, doesn't mean it's correct.

I don't think we should deprecate this. Doesn't it make more sense to drop MutableRefObject in the future instead and let RefObject be the mutable one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reviewed the history prior to making the recommendation. However there isn't really a way to know if the intended use is user managed vs react-managed, which is unfortunate.

Changing RefObject to be representable with MutableRefObject allows for deprecation. The reverse isn't possible.

I'm saying its "wrong" because really you can change it as you see fit and applying magic typing to try to signify if something is readonly or not is just confusing. I'm saying its "wrong" because we created a weird mechanism in the types that are inconsistent with react itself and have been since day one.

Also, saying the ref is 'readonly' when you pass it to something that clearly modifies the value, also breaks most of the ways that readonly is used, which is that it lets you know that the thing you are giving it to doesn't mutate it. To your example of a ReadonlyArray, if an API had a doFoo() that returned {foo: ReadonlyArray<T>} then I would assume that the inner array would never change out from under me. But in the analogy, you're allowing it to change by react.

@eps1lon
Copy link
Collaborator

eps1lon commented Mar 27, 2023

#64896 for an alternate proposal.

Keeping RefObject since that's shorter. RefObject will become mutable an no longer contain | null. We'll deprecate MutableRefObject later.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Apr 21, 2023
@typescript-bot
Copy link
Contributor

@ericanderson I haven't seen any activity on this PR in more than three weeks, and it still has problems that prevent it from being merged. The PR will be closed on Apr 27th (in a week) if the issues aren't addressed.

@typescript-bot
Copy link
Contributor

@ericanderson To keep things tidy, we have to close PRs that aren't mergeable and don't have activity in the last month. No worries, though — please open a new PR if you'd like to continue with this change. Thank you!

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

Labels

Abandoned This PR had no activity for a long time, and is considered abandoned Author is Owner The author of this PR is a listed owner of the package. Critical package The CI failed When GH Actions fails

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants