Skip to content

Template literal types fail in mapped types #42192

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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