arahfahrrad
arahfahrrad

Reputation: 165

Overwriting a Javascript function in Typescript

I'm using Angular 5 and typescript and included the code editor codemirror into my page.

I want to overwrite a nested functionality: Codemirror.hint.function

In javascript it looks like:

Codemirror.hint.function = function(param) = {
...
}

How can I do this in typescript? Because it is nested, I can't define a simple interface.

I want to define an own autocompletion for this editor.

solved it: Codemirror specific solution: Code: stackblitz

Upvotes: 0

Views: 721

Answers (1)

user4676340
user4676340

Reputation:

You can use this

Object.defineProperty(Codemirror.hint, 'function', {value: () => {/* your override */}});

Although I highly doubt that an object can have a function function, since it is a javascript keyword.

EDIT I don't know why or how, but the typescript definition in your blitz didn't declare CodeMirror as a global variable. Probably minification, but I won't search further.

So I added the script with a CDN in index.html, and now it works.

Here is the stackblitz.

Upvotes: 1

Related Questions