Problem with custom plugin typescript declaration on Ionic 2


#1

Hello all,

I’m creating a custom Cordova plugin and trying to test it with a simple Ionic 2 project.
I created a typings definition for the plugin and bundled it as I see in many others plugins (folder types on plugin and declaring it on package.json under “types”).

My problem is that the Ionic 2 don’t find the definition, no matter how I try to include it.
I already tried to include in many ways with no luck (in package.json, as a typings definition, importing from a definition inside src folder), and the method I see more correct is using the src/declarations.d.ts.
I read a lot of documentation but I fail to find a successful way to include the definition in the file, anyone have already tried this and know how I can proceed?

If I write the definition inside the declarations.d.ts directly like:

interface TestPlugin {
echo( msg: string ): void;
}
interface Window {
test: TestPlugin;
}

Everything works and the references are found, but if I try to import/export/declare using a reference to the declaration file in the plugin folder, it never compile.

If anyone could show me the correct way to declare the reference I will be very glad =)

Thank you,


#2

For one thing, I believe you must export them where they are declared in order to be able to import them from anywhere else. Otherwise, they are visible only within their own file.