One option is to use bracket notation, as suggested in a comment.
rrule.ts:
export default interface RRule {Frequency: string; Weekday: string};
recurring-event.ts:
import RRule from "./rrule";
export interface RecurringEvent {
title: string;
color: any;
rrule?: {
freq: RRule["Frequency"];
bymonth?: number;
bymonthday?: number;
byweekday?: RRule["Weekday"][];
};
}
In vanilla with JSDoc:
rrule.js:
/**
* @typedef {Object} RRule
* @property {string} RRule.Frequency
* @property {string} RRule.Weekday
*/
/** @type {RRule} */
const RRule = {Frequency: "", Weekday: ""};
export default RRule;
recurring-event.js:
/** @typedef {import("./rrule").RRule} RRule */
/**
* @typedef {Object} RecurringEvent
* @property {string} title
* @property {any} color
* @property {{
* freq: RRule["Frequency"];
* bymonth?: number;
* bymonthday?: number;
* byweekday?: RRule["Weekday"][];
* }} [rrule]
*/
/** @type {RecurringEvent} */
const recurringEvent = {
title: "",
color: "",
rrule: {
freq: "",
bymonth: 0,
bymonthday: 0,
byweekday: [""],
},
};
jsconfig.json:
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"checkJs": true,
"allowJs": true,
"declaration": true,
"target": "ES2016",
"module": "ESNext",
"moduleResolution": "node",
"outDir": "dist"
},
"include": [
"./src/*.js"
],
"verbose": true
}
Command: tsc --project ./jsconfig.json
.
['Frequency']
syntax with types to access the member like that. – Dumbarton