0

I have declared an enum in a d.ts file

declare enum myenum
{
    TYPE_ONE,
    TYPE_TWO,
}

declare class MobileAPI extends NSObject {....}

Now I am accessing the enum in a .ts file like bellow.

this.mobileAPI.addType(myenum.TYPE_ONE,NSString.stringWithString("someString"));

I can compile the app, but getting following JS error

JS ERROR ReferenceError: Can't find variable: myenum

What's am I doing wrong here, please share some idea on this

2 Answers 2

1

What's am I doing wrong here, please share some idea on this

You are creating a declaration. These should only be used if you have corresponding JavaScript code available.

Fix

Dont use declare and use a file .ts (not .d.ts)

enum myenum // Fixed
{
    TYPE_ONE,
    TYPE_TWO,
}

More

If you are not the author of the .d.ts file, make sure you load the corresponding JS for the .d.ts file.

Sign up to request clarification or add additional context in comments.

2 Comments

I am creating a nativescript plugin for native iOS libarary. .d.ts file is auto generated
Then make sure the corresponding JS is loaded.
0

You can do inside your d.ts :

export const enum myenum {
  TYPE_ONE = "TYPE_ONE",
  TYPE_TWO = "TYPE_TWO"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.