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

Adding template literal key to spread object is ignored #60975

Closed
niedzielski opened this issue Jan 15, 2025 · 2 comments
Closed

Adding template literal key to spread object is ignored #60975

niedzielski opened this issue Jan 15, 2025 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@niedzielski
Copy link

🔎 Search Terms

"template literal" spread, spread "string literal"

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "spread"; present in nightly and goes back to at least v4.5.5.
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250115#code/MYewdgzgLgBAbgQwE4EsECMA2BTAXDAAxQBMB9AEgG90UBzFMKAXwJgF4YByE0gRgCYAzJwDcAKFCRYEAA5JsCYuxiUAdOsoZg+MAFdMmJgBoYAbUSoMOALr4oSXdibiAFLPmKYEBFBQQAZijYECqmpPjQqGC0tjB6BkwAlGJAA

💻 Code

const variable: `id_${bigint}` = 'id_123';
const spread = {...{abc: null}, [variable]: true};
(spread satisfies {[_: string]: null})

🙁 Actual behavior

No errors. spread is incorrectly inferred as:

const spread: {
    abc: null;
}

🙂 Expected behavior

spread is inferred as:

const spread: {
    [_: `id_${bigint}`]: boolean;
    abc: null;
}

Causing the satisfies test to fail.

Additional information about the issue

Omitting the template literal errors correctly:

const variable = 'id_123';
const spread = {...{abc: null}, [variable]: true};
(spread satisfies {[_: string]: null})

Attempting to insert the template literal errors correctly:

const variable: `id_${bigint}` = 'id_123';
const spread: {[_: string]: null} = {...{abc: null}};
spread[variable] = true
@jcalz
Copy link
Contributor

jcalz commented Jan 15, 2025

Effectively a duplicate of #38663. You're using a template literal key instead of a union, but the same thing happens: it is widened all the way to string as per #13948 ( #13948 (comment) ) and then it ends up disappearing in spread due ( #38663 (comment) )

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 15, 2025
@typescript-bot
Copy link
Collaborator

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

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants