Skip to content

template literals fail to type check as string literals #17595

Description

@spoonscen

TypeScript Version: 2.4.0

Code

type Foo = 'lol'

const barr: Foo = `lol`
// Type 'string' is not assignable to type '"lol"'.

https://www.typescriptlang.org/play/#src=type%20Foo%20%3D%20'lol'%0A%0Aconst%20barr%3A%20Foo%20%3D%20%60lol%60

Expected behavior:

type Foo = 'lol'

const barr: Foo = `lol`
// No error

Actual behavior:

type Foo = 'lol'

const barr: Foo = `lol`
// Type 'string' is not assignable to type '"lol"'.

Activity

  1. ikatyang commented on Aug 4, 2017

    @ikatyang
    Contributor

    Duplicate of #16592.

  2. DanielRosenwasser commented on Aug 4, 2017

    @DanielRosenwasser
    Member

    Thanks for finding that Ika (@ikatyang)!

  3. ghost closed this as completedin #17704on Aug 10, 2017
  4. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions