Skip to content

Computed string literal can't be used as generic argumentΒ #58494

Closed
@DimaIT

Description

@DimaIT

πŸ”Ž Search Terms

"string literal is not assignable to parameter of type", "generic string literal argument"

πŸ•— Version & Regression Information

  • This changed between versions 5.1.6 and 5.2.2

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABMMAeAKgPgBQEMBOA5gFyLoCUp6iA3gFCKOL4CmUI+SBhA3HQL506EBAGcoiXIgC8iAOQBGOXxFhxiAEYzJiANTzEAJmVCU2AAYASGhv6IAzOfI8gA

πŸ’» Code

function fn<T>(arg: T): T {
    return arg;
}

const a = '1';
const b = a + ' 2';

fn(`${b} 3`);

πŸ™ Actual behavior

Argument of type '`${string} 3`' is not assignable to parameter of type '"1 2 3"'.

πŸ™‚ Expected behavior

No errors are expected

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions