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

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/53633 #44451

Closed
icecream17 opened this issue Jun 5, 2021 · 6 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@icecream17
Copy link

icecream17 commented Jun 5, 2021

I'm super tired of debugging today.Feel like I have the most complicated bugs in the world
I'll update this later.Sorry

(See DefinitelyTyped/DefinitelyTyped#53633 (comment) for now)

Bug Report

🔎 Search Terms

intersection
pick / setState

This issue is similar: #44315
I found this: #28080 but it's different since the first line in the code below seems to work. But the issue code doesn't work? Weird.

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground Link with code below

💻 Code

// React setState handler is typed like this:
function setState<State, Props, K extends keyof State> (
    state: 
        ((prevState: Readonly<State>, props: Readonly<Props>) => (Pick<State, K> | State | null))
      | (Pick<State, K> | State | null),
    callback?: () => void
) {}

type ThisState = { a: number, b: number }

setState({ a: 7 }) // ok
setState(() => ({ a: 7 })) // ok
setState((prevState: ThisState) => Math.random() > 0.5 ? prevState : {}) // ok
setState((prevState: ThisState) => Math.random() > 0.5 ? prevState : { a: 7 }) // error

🙁 Actual behavior

The last call has an error

🙂 Expected behavior

No error

@MartinJohns
Copy link
Contributor

You forgot to fill out the issue template.

@icecream17
Copy link
Author

screenshot


image


I didn't forget, I just procrastinated. It's now filled out

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 7, 2021
@RyanCavanaugh
Copy link
Member

Everything here is proceeding according to the declaration of the function. I don't see any defect being demonstrated here.

@icecream17
Copy link
Author

icecream17 commented Jun 7, 2021

I don't understand...
If { a: 7 } works and prevState | {} works then why not prevState | { a: 7 }?

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@icecream17
Copy link
Author

icecream17 commented Jun 9, 2021

Wait, no one responded to my question, what should I do?

Update: I realized something, nevermind, the close was valid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants