I'm not using TypeScript as the primary language for this application, but as the type-hinting assist for JetBrains' WebStorm alongside JSDocs. I'm also using the keyMirror utility to create quasi-enum object literals.
Given the following:
//enums.js
var keyMirror = require('keyMirror');
module.exports = {
CRUDVerbs: keyMirror({ //keymirror mirrors the key to value in objects
CREATE: null,
READ: null,
UPDATE: null,
DESTROY: null
}
}
//app.js
var enums = require('enums.js');
var CrudTypes = enums.CRUDVerbs;
/** @type {??????????} **/
var returnedVal = functionFromElsewhere();
if(returnedVal === CrudTypes.CREATE) {
//code
} //..etc...
What is the type of returnedVal and of CrudTypes.CREATE, for the purposes of defining it in e.g. enums.d.ts?
The code for keyMirror assigns the property key to the value:
Therefore, the type of
returnValandCrudTypes.CREATEshould bestring.Note that
Object.keys(...)returnsstring[]in TypeScript and that the following code outputsstringfor all the keys: