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

The type 'TemplateStringsArray' is undefined. #533

Closed
rezyaev opened this issue May 11, 2020 · 3 comments
Closed

The type 'TemplateStringsArray' is undefined. #533

rezyaev opened this issue May 11, 2020 · 3 comments

Comments

@rezyaev
Copy link

rezyaev commented May 11, 2020

Modern JavaScript has tagged template literals feature. It is a function that allows processing of back ticks strings.

First argument for that function is of type TemplateStringsArray. And jsdoc plugin gives "The type 'TemplateStringsArray' is undefined." error when documenting it.

Example:

/**
 * @param {TemplateStringsArray} strings // The type 'TemplateStringsArray' is undefined. eslint(jsdoc/no-undefined-types)
 * @param  {...any} expressions
 * @returns {string}
 */
export const html = (strings, ...expressions) =>
	strings
		.reduce((result, string, index) => {
			const expression = Array.isArray(expressions[index])
				? expressions[index].join('')
				: expressions[index];

			return expression
				? `${result}${string}${expression}`
				: `${result}${string}`;
		}, '')
		.replace(/(\t|\n)+/g, '');

Function usage:

const world = 'world';
html`<div>Hello, ${world}</div>`; // '<div>Hello, world</div>'
@rezyaev
Copy link
Author

rezyaev commented May 11, 2020

ESlint version: 7.0.0
Jsdoc-plugin version: 25.0.1
ESLint config:

"plugins": ["immutable", "jsdoc"],
"env": {
	"browser": true,
	"es6": true
},
"parserOptions": {
	"ecmaVersion": 2020,
	"sourceType": "module"
}

@brettz9
Copy link
Collaborator

brettz9 commented May 11, 2020

This is not related to tagged templates being supported or not. The issue is that our code for the jsdoc/no-undefined-types rule currently relies on finding TemplateStringsArray as a defined (global) variable. Currently, you can work around this by defining a TemplateStringsArray typedef in that file or adding it to globals in your config file or inline at the top of your file with /* globals */.

For the ability for files to auto-detect which variables are in scope (e.g., if you have a class or typedef definedTemplateStringsArray somewhere in another file), you can follow #99 or #178 to follow about the desire for it to support local variables (e.g., if you had a non-global TemplateStringsArray class before you used the type).

Closing as that should resolve, though feel free to comment further as needed.

@brettz9 brettz9 closed this as completed May 11, 2020
@rezyaev
Copy link
Author

rezyaev commented May 11, 2020

Okay, thanks, i will add it to globals in config

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

2 participants