Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String literal expected. when importing in typescript

Tags:

typescript

import * as app from `${process.cwd()}/server`

It give me the error:

[ts] String literal expected.

Can I not interpolate strings when importing?

like image 579
Shamoon Avatar asked May 16 '18 20:05

Shamoon


People also ask

What is string literal in TypeScript?

The string literal type allows you to specify a set of possible string values for a variable, only those string values can be assigned to a variable. TypeScript throws a compile-time error if one tries to assign a value to the variable that isn't defined by the string literal type.

How do you use string literals in TypeScript?

Hence, you can treat a variable that has a string literal type like a variable of type string . You can access properties, call methods, and use operators, just as you would with regular strings: const eventName: "click" | "mouseover" = "click"; eventName. length; // 5 eventName.

What is string literal with example?

A string literal is a sequence of zero or more characters enclosed within single quotation marks. The following are examples of string literals: 'Hello, world!' '10-NOV-91' 'He said, "Take it or leave it."'

How do you declare a string literal?

The best way to declare a string literal in your code is to use array notation, like this: char string[] = "I am some sort of interesting string. \n"; This type of declaration is 100 percent okey-doke.


1 Answers

This is not legal syntax in ES6 modules or in TypeScript. Part of the ES6 module spec is that dependencies are always statically resolvable.

like image 109
Ryan Cavanaugh Avatar answered Sep 18 '22 14:09

Ryan Cavanaugh