Skip to content

Template literal types fail in mapped types #42192

Closed
@hassannteifeh

Description

@hassannteifeh

TypeScript Version: 4.1.3

Search Terms: template literal types

type Pseudo = `&:${string}` 

const AmIPseudo1: Pseudo = '&:test' // Passes as expected
const AmIPseudo: Pseudo = '&' // Fails as expected

type PseudoDeclaration = {
    [key in Pseudo]: string
}

// No Errors
const test: PseudoDeclaration = {
    'someKey' : 'someValue'
}

Expected behavior:

test should not be able to pass the type-checking as its key 'someKey' is not of type Pseudo.

Actual behavior:

test passes the type-checking.

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