Royi Namir
Royi Namir

Reputation: 148524

NativeScript Permissions - Cannot find name 'android'?

I'm using the Spartadigital NativeScript Permissions plugin

I've also did :

tns plugin add @spartadigital/nativescript-permissions

And inside the ts file :

import {Permissions} from '@spartadigital/nativescript-permissions';

However when I run tns run android : I get :

node_modules/@spartadigital/nativescript-permissions/permissions.android.d.ts(2,37): error TS2304: Cannot find name 'android'.

node_modules/@spartadigital/nativescript-permissions/permissions.android.d.ts(3,34): error TS2304: Cannot find name 'android'. node_modules/@spartadigital/nativescript-permissions/permissions.ios.d.ts(24,47): error TS2552: Cannot find name 'NSObject'. Did you mean 'Object'? node_modules/@spartadigital/nativescript-permissions/permissions.ios.d.ts(24,67): error TS2304: Cannot find name 'CLLocationManagerDelegate'. node_modules/@spartadigital/nativescript-permissions/permissions.ios.d.ts(26,20): error TS2304: Cannot find name 'CLLocationManagerDelegate'.

Looking at the file , I see that it doesn't know android :

enter image description here

Nor other IOS objects :

enter image description here

I already have tns-platform-declarations :

enter image description here

Question:

Why doesn't it recognize those keywords and how can I fix it ?

package.json

ts.config

Upvotes: 2

Views: 3723

Answers (2)

Sam R
Sam R

Reputation: 143

an easy answer would be to add declare var android to the top of the typescript file (under imports) you are calling it in. NativeScript knows where to get android from once its compiled.

Upvotes: 1

Brad Martin
Brad Martin

Reputation: 6167

You should add the tns-platform-declarations module to your project, this will give you the typings for the native namespaces, classes, etc and enable intellisense also for what is provided by this module.

https://www.npmjs.com/package/tns-platform-declarations

Upvotes: 4

Related Questions