Skip to content

Can't use nullable strings in template literal #2918

Closed
@mattjohnsonpint

Description

@mattjohnsonpint

Bug description

Template literal strings can interpolate most scalar value types, including strings, numbers, booleans, etc.

However, trying to use a nullable string in a template literal currently leads to a compiler error.

Steps to reproduce

const x: string | null = "abc";  
const s = `test: '${x}'`
ERROR TS2685: The 'this' types of each signature are incompatible.
     :
   2 │ const s = `test: '${x}'`
     │                     ~
     └─ in assembly/index.ts(3,23)
     :
 644 │ toString(): String {
     │ ~~~~~~~~~~~~~~~~~~
     └─ in ~lib/string.ts(644,3)

The error is confusing, as it doesn't explain why there's an incompatibility, and there's only one value the user is putting in the template literal.

AssemblyScript version

v0.27.36

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions