Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am attempting to include when.js (a public Promise library on github that can be found here) as a property of Cesium (a public 3-D modelling framework described here) in a Typescript definition file I have for the Cesium library. This is because I am trying to convert some Javascript files from a project that utilizes Cesium to Typescript, and the Cesium.js code that is referenced has the below code snippet included. I am at a loss at how to declare when.js in the d.ts file, however. It doesn't appear to be a class, and I don't think it's an interface. How should I go about this property - what kind of object is it?

JavaScript
(function(define) { 'use strict';
define('ThirdParty/when',[],function () {
	var reduceArray, slice, undef;

	//
	// Public API
	//

	when.defer     = defer;     // Create a deferred
	/* more when.otherProperties set here */

    /**
	 * Register an observer for a promise or immediate value.
	 *
	 * @param {*} promiseOrValue
	 * @param {function?} [onFulfilled]
	 * @param {function?} [onRejected]
	 * @param {function?} [onProgress]
	 * @returns {Promise}
	 */
	function when(promiseOrValue, onFulfilled, onRejected, onProgress) {
		// Get a trusted promise for the input promiseOrValue, and then
		// register promise handlers
		return resolve(promiseOrValue).then(onFulfilled, onRejected, onProgress);
	}
    /* more functions defined here, including a 'defer' function */


What I have tried:

Currently I can get code referencing this to work if I declare a class called "when" in the Cesium.d.ts file I have. The only problem is that in this case "when" is a constructor, but as is clearly defined in the code snippet, the function "when" returns a Promise.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900