nstudio / nativescript-checkbox

NativeScript plugin for checkbox UI component
Other
119 stars 56 forks source link

Android cannot get checkbox with id #19

Closed mounirka closed 7 years ago

mounirka commented 7 years ago

Hi guys, i followed the small tutorial you made, but when i do

let checkBox = topmost().getViewById('yourCheckBoxId');
checkBox.toggle();

It says that Property 'toggle' does not exist on type 'View'. How can i solve? thank you

bradmartin commented 7 years ago

Likely TS issue, need to update/extend the d.ts to put that property on the checkbox. You could also try:

let checkbox: CheckBox = ... assuming you have import { CheckBox } from nativescript-checkbox on the file. This way you assign the type to the variable, again the definition might need updating. Have to check on that later.

mounirka commented 7 years ago

Even doing: let checkbox: CheckBox = is say that type View is not assignable to type Checkbox.

bradmartin commented 7 years ago

Yea so the typings need to be updated for the compiler to recognize the prop.

You might try casting it this way: let checkbox = <CheckBox>... I forget how the compiler recognizes the types with casting. There's even casting to any which will for sure at least silence the compiler to prevent any errors thrown.

bradmartin commented 7 years ago

@mounirka I think I told you wrong it would be let checkbox = (<CheckBox>topmost()....) to do the correct type assignment. If I get time I'll update the typings to not require this but for now that should work to assign the type to the view instance.