-
Notifications
You must be signed in to change notification settings - Fork 109
Handle callable interfaces / call signatures #413
Comments
We have a precedent for #2 here: tsickle/src/type-translator.ts Line 432 in 989beac
That handles indexable interfaces as long as they don't have other fields. |
Oh actually maybe that code already implements #2 ? |
Looks like it, but seems like this has issues for at least the callable that I ran into. Which I of course don't remember :-( |
Any traction on this? I would assume your example would be written as an externs file like so: /**
* @param {number} a
* @return {string}
*/
function ToStringer(a);
/** @type {string} */
ToStringer.prop; If, as an author, you have control over the .d.ts file, you can work around this issue using /**
* Loads a single module.
* @param module Module to load
* @return The loaded module
*/
declare function require(module: string): any;
/**
* Asynchronously loads the specified modules.
* @param modules Required modules to load.
* @param ready Called when required modules are ready.
* @param errback Called when required modules are ready.
*/
declare function require(
modules: string[], ready?: () => void,
errback?: (error: any) => void): void;
declare namespace require {
function config(
params: AMDLoader.IConfigurationOptions, shouldOverwrite?: boolean): void;
} Which generates the following externs: /**
* Loads a single module. / Asynchronously loads the specified modules.
* @param {string|!Array<string>} module_or_modules Module to load / Required modules to load.
* @param {(undefined|function(): void)=} ready Called when required modules are ready.
* @param {(undefined|function(?): void)=} errback Called when required modules are ready.
* @return {?|void} The loaded module
*/
function require(module_or_modules, ready, errback) {}
/**
* @param {!AMDLoader.IConfigurationOptions} params
* @param {(undefined|boolean)=} shouldOverwrite
* @return {void}
*/
require.config = function(params, shouldOverwrite) {}; |
Did you check if that works in Closure Compiler? I.e. can you use |
No, you're right. That doesn't work. Given the following externs: /** @record */
class _ToStringerProps {
constructor() {
/** @type {string} */
this.prop;
}
}
/** @typedef {function(string): !ToStringer} */
let _ToStringerFunc;
/** @typedef {_ToStringerProps|_ToStringerFunc} */
let ToStringer;
/** @type {!ToStringer} */
let toStringer; And the following source code: const /** string */ str1 = toStringer('a').prop;
const /** string */ str2 = toStringer.prop; We get:
Again, if you don't care about using the Is there a sister Issue for the Closure Compiler to support this? |
To be clear, I first tried to just use my first externs but that didn't work so I was trying some other things. You can't have a function which is not a constructor be used as a type in Closure. |
Re sister issue, I don't have one handy, but feel free to link here if you
find it :-)
|
Uh oh!
There was an error while loading. Please reload this page.
Currently generates an interface including
prop
, but dropping the call signature.Options:
{?}
for the time beingFor the last item, it's possible to re-open a type through a value in Closure:
The last idea might be overkill.
The text was updated successfully, but these errors were encountered: