Skip to content

String literal rename doesn't work in object unions #41489

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

Open
aspirisen opened this issue Nov 11, 2020 · 4 comments
Open

String literal rename doesn't work in object unions #41489

aspirisen opened this issue Nov 11, 2020 · 4 comments
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol
Milestone

Comments

@aspirisen
Copy link

aspirisen commented Nov 11, 2020

TypeScript Version: 4.2.0-dev.20201109

Search Terms:
String literal rename

Code

type Actions = { type: 'one', payload: number } | { type: 'two', payload: boolean }
const q: Actions = { type: 'one', payload: 1 }

Expected behavior:
Renaming of values of 'type' fields should also rename the value in actual variable. For example if I rename 'one' in the type Actions TS should also rename the value of type field in q variable, and vice versa.

Actual behavior:
Looks like renaming doesn't start at all

Playground Link:
https://www.typescriptlang.org/play?ts=4.2.0-dev.20201109#code/C4TwDgpgBAggxsAlgewHYGcoF4oG8qiQBcUA5GhKQDRRgCGIANsnQCYmoCuAtgEYQAnKAF8oAHzwFwEEqWAB3ZNVoNmbEr2TJGEOqhEAoOGnTAoARxLwkJ7JMIyyFZfSYt2UAIwigA

Related Issues:
#5602
#39298

@a-tarasyuk
Copy link
Contributor

It seems, renaming the key works
41489

@aspirisen Could you provide steps to reproduce?

@aspirisen
Copy link
Author

@a-tarasyuk i am talking about the string literal rename, changed the ticket description

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol labels Nov 12, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 12, 2020
@wclr
Copy link

wclr commented Dec 10, 2020

@RyanCavanaugh

I think this could be quite a priority, a great number of people use typed actions/events (in redux, ect). They just don't know that it could be refactored without pain and additional replacement work.

@qwertysk
Copy link

qwertysk commented Dec 21, 2022

@aspirisen try this workaround

interface A1 { type: 'one', payload: number }
interface A2 { type: 'two', payload: boolean }

type Actions = A1 | A2

const q: Actions = { type: 'one', payload: 1 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol
Projects
None yet
Development

No branches or pull requests

5 participants