Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Found template literal expression having a non-string type JS-0378 #276

Open
philipjonsen opened this issue Mar 24, 2022 · 0 comments
Open

Comments

@philipjonsen
Copy link

philipjonsen commented Mar 24, 2022

DESCRIPTION
Using only string values in placeholders is recommended as otherwise, the value may be wrongly displayed; for example, if an object value is directly included in a string, it will be shown as [object Object]. Using only string values can also ensure that null or undefined values are not directly displayed.

With template literals, an expression can be embedded in a placeholder. A placeholder is represented by ${}, with anything within the curly brackets treated as JavaScript and anything outside the brackets treated as a string.

Examples
Bad Practice
const arg1 = [1, 2];
const msg1 = arg1 = ${arg1};
const arg2 = { name: 'Cryptosweden' };
const msg2 = arg2 = ${arg2 || null};

Recommended
const arg = 'Cryptosweden';
const msg1 = arg = ${arg};
const msg2 = arg = ${arg || 'default'};

const stringWithKindProp: string & { _kind?: 'MyString' } = 'DeepSource';
const msg3 = stringWithKindProp = ${stringWithKindProp};

any
any2
any3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant