'$with' in JavaScript is migrated to TypeScript

51 Views Asked by At

There is the following class given in Javascript:

 'MyInsetsProvider': new yfiles.lang.ClassDefinition(function() {
        /** @lends {DemoGroupStyle.MyInsetsProvider.prototype} */
        return {

            '$with': [yfiles.input.INodeInsetsProvider],

            /** @return {yfiles.geometry.Insets} */
            'getInsets': function(/**yfiles.graph.INode*/ item) {
                var  margin = 5;
                return new yfiles.geometry.Insets(
                    BORDER_THICKNESS + margin, HEADER_THICKNESS + margin,
                    BORDER_THICKNESS + margin, BORDER_THICKNESS + margin);
            }
        };
    }),

I have three questions to it:

1, what is the 'function()' at the beginning? Is it a class and a function at the same time?

2, what does the '$with' mean?

3, how can we migrate it into TypeScript?

1

There are 1 best solutions below

0
On
  1. function() defines a function. In this case it looks like a callback that when called returns an object. Nope, it's not a "proper" class although it appears to define a yfiles class.
  2. "$with" is a string being used as an object key
  3. TypeScript is a superset of JavaScript. Change the file extension to .ts and run it through a TypeScript compiler and it'll work.