I am currently working on a chrome extension with multiple content scripts using typescript (I'm new to both js and ts). Inside of the content scripts I have two functions with the same name. I basically need to know how to "allow" this:
//FileA:
function methodxyz(param: Element): void {
//FileB:
function methodxyz(param: Element): void {
I have read in other articles to either put export { };
on the top of my file or to put export
in front of my functions. But then I get an error when using my extension that says: Uncaught SyntaxError: Unexpected token 'export'
or something similar.
I think there is an option in typescript to combine all of your files into one .js file which I would assume causes that error to be thrown, but as I don't want that functionality I hope someone can help me with this :)
CodePudding user response:
Typescript has Namespaces for that.
From reading the comments, just wanted to say something on JS & TS. I think an important thing to understand about javascript is that there are a lot of different runtimes going around (different browser versions, node versions, etc.), and they don't all support all the latest features of the language specification, which are defined in the ECMAScript Language Specification.
So as a developer, to be able to use the newest features of the language, while not worrying about being compatible with every runtime that is going to run my code, you can transpile your code into an older version to make it compatible. That brings the advantage that you can program with the newest, flashy things.
You can take a look at https://babeljs.io/
Once you do that, you can follow more JS standards instead of namespaces by writing your code as Modules
, which is something supported natively in JS and TS.
Read about modules in TS.