Skip to content

Template literal types with decorator crashes in emitΒ #46406

@AdrianAbramczyk

Description

@AdrianAbramczyk

Bug Report

πŸ”Ž Search Terms

Template literal type annotation

πŸ•— Version & Regression Information

  • This is a crash
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about annotation / literal.

⏯ Playground Link

Playground link with relevant code (See console)

πŸ’» Code

import "reflect-metadata";

const formatMetadataKey = Symbol("format");

function format(formatString: string) {
  return Reflect.metadata(formatMetadataKey, formatString);
}

class Greeter {
  // Here : Can't use a literal type with an annotation
  @format("Hello, %s")
  greeting: `${string}`;
  
  constructor() {
    this.greeting = '#XXXX';
    console.log('this.greeting', this.greeting);
  }
}

new Greeter();

πŸ™ Actual behavior

When using a template literal type with an annotation I get the following error in the console :

Error: Debug Failure. Unexpected node.
Node TemplateLiteralType was unexpected

Because the template literal type is not currently supported :

return Debug.failBadSyntaxKind((node as LiteralTypeNode).literal);

πŸ™‚ Expected behavior

I should not get an error.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFix 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