Код: Выделить всё
class BaseClass {
/**
* @abstract
* @returns {string}
*/
static get prefix() { throw Error('must be overridden'); }
/**
* @abstract
* @returns {string}
*/
static get suffix() { throw Error('must be overridden'); }
/**
* @template {typeof BaseClass} T
* @this T
* @returns {`${T['prefix']}_${T['suffix']}`}
*/
static get key() { return `${this.prefix}_${this.suffix}`; }
}
class Foo extends BaseClass {
/** @override */
static get prefix() { return /** @type {const} */ ('foo') };
/** @override */
static get suffix() { return /** @type {const} */ ('bar') };
}
Foo.key;
// `Foo.key` should be inferred as `'foo_bar'` but is only inferred as `${T['prefix']}_${T['suffix']}`.
. case. < /p>
Код: Выделить всё
class BaseClass {
/**
* @abstract
* @returns {string}
*/
get prefix() { throw Error('must be overridden'); }
/**
* @abstract
* @returns {string}
*/
get suffix() { throw Error('must be overridden'); }
/**
* @returns {`${this['prefix']}_${this['suffix']}`}
*/
get key() { return `${this.prefix}_${this.suffix}`; }
}
class Foo extends BaseClass {
/** @override */
get prefix() { return /** @type {const} */ ('foo') };
/** @override */
get suffix() { return /** @type {const} */ ('bar') };
}
const foo = new Foo();
foo.key;
// the tooling correctly knows `foo.key` is `'foo_bar'`
Цель - наведите static getters в таком способе, который непосредственно ссылается. Правильный постоянный тип. Есть ли способ сделать это со статическими классами через jsdoc?
Подробнее здесь: https://stackoverflow.com/questions/796 ... sing-jsdoc