I have the following code snippet, my question is how do I keep the literal type information of knowLiteral without having to spell out the type like I am doing right now?
// @ts-check
/**
* @typedef {Readonly<Record<string, string>>} ReadonlyStringRecord
*/
/**
* @template {ReadonlyStringRecord} T
*/
class Main {
/**
* @param {T} knowLiteral
*/
constructor(knowLiteral) {
/**
* @readonly
* @type {T}
*/
this.knowLiteral = knowLiteral;
}
}
// how not to have to write this?
/**
* @extends {Main<{
* this_is_know: '42'
* }>}
*/
class Main2 extends Main {
constructor() {
const knowLiteral = /** @type {const} */ ({ 'this_is_know': '42' });
super(knowLiteral);
}
testFunc() {
//this should (and does) error.
let x = this.knowLiteral.this_is_not_defined;
}
}