How to fix “Multiple methods named 'reload' found with mismatched result, parameter type or attributes…” - react-native

enter image description hereI'm compiling a react-native project.
I'm facing a error of "Multiple methods named 'reload' found with mismatched result, parameter type or attributes...".
- (void)selectDevMenuItemWithKey:(NSString *)key onBridge:(id)bridge
{
RCTAssertMainQueue();
RCTDevSettings *devSettings = [self _moduleInstanceForBridge:bridge named:#"DevSettings"];
if ([key isEqualToString:#"dev-reload"]) {
[bridge reload];
} else if ([key isEqualToString:#"dev-remote-debug"]) {
devSettings.isDebuggingRemotely = !devSettings.isDebuggingRemotely;
} else if ([key isEqualToString:#"dev-live-reload"]) {
external information:
react-native for sdkVersion 27.0.0....
Pre-downloading: ExpoKit from http://github.com/expo/expo.git, tag ios/2.5.10
I tried to change this "sdkVersion": "27.0.0" to "28.0.0"..."32.0.0" in app.json but got same error.
I didn't find solution ...

Related

How to access the file system using window.resolveLocalFileSystemURL in Typescript? Ionic 3

Following the documentation for the File plugin, I can see the paragraph which explains how to append data to a log file. This is the example code:
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (dirEntry) {
...
}, onErrorLoadFs);
However I get an error
Property 'resolveLocalFileSytemURL' does not exist on type 'Window'.
Does anyone know why this would happen? Are there alternative ways to append to a file using this plugin?
To access the files of a directory use listDir -
https://ionicframework.com/docs/native/file/:
import { File } from '#ionic-native/file';
constructor(private file: File) { }
...
this.file.listDir('file:///', this.file.dataDirectory)
.then(_ => console.log('Directory exists'))
.catch(err => console.log('Directory doesnt exist'));

tslint error Shadowed name: 'Observable'

I am getting the following error when running tslint that I wasn't getting before..
ERROR: C:/...path..to../observable-debug-operator.ts[27, 13]: Shadowed name: 'Observable'
I followed this tutorial for adding a debug operator to Observable and it is working fine except I am getting this lint error. I had been using this debug operator for a while without getting the lint error and I'm not sure why I am getting it now.
Here is the code at line 27 to amend the type definition with the debug method
declare module 'rxjs/Observable' {
interface Observable<T> { // line 27
debug: (...any) => Observable<T>;
}
}
Does anyone know how I can clear this lint error? Thank you!
Here is a quick example of variable shadowing, to make the warning clear.
var x = 4;
function example() {
var x = 5; // x is shadowing the outer scope's x variable
}
If you are declaring an extension to an interface (i.e. both instances of Observable have the same common root) you are not technically shadowing, but if you have an Observable at multiple levels, it may make it unclear to which you are referring.
You can switch off shadowing warnings using the option:
"no-shadowed-variable": [
true,
{
"class": true,
"enum": true,
"function": true,
"interface": false,
"namespace": true,
"typeAlias": false,
"typeParameter": false
}
]
Is interface shadowing a problem in TypeScript?
Not really - you would catch a situation where an interface was declared inside a function, which you would also catch because if it was a problem the TypeScript compiler would already be telling you there is a problem... i.e. the member list would show you the correct members in both scopes.
Interfaces are also erased - so there is no post-compile confusion, for example if someone were to use your TypeScript library in a JavaScript program.
I'm happy to change my opinion if someone can supply a realistic example of where interface shadowing would cause a problem.
Basically, Fenton explains it quite well with his example.
Shadowing occurs with naming collisions.
So why not name a nested variable/parameter something else than x? ;)
My example:
...
.retryWhen(error => {
return error
.mergeMap((error: any) => {
if (error.status === 500) {
...
You see, a lot of error parameters.
Not sure how this fixed it but I reinstalled my package dependencies including tslint and now I don't get the error anymore. Thanks for your time trying to help :)

How to catch undeclared variable in React with ESLint?

I noticed the other day that ESLint lets me use undefined variables. Here's a simple example:
import React from 'react';
export default class test extends React.Component {
render(){
var a = b;
var b = 1;
return <h1>{a}</h1>
}
}
Visual Studio Code with ESLint plugin does not draw a red line under that first 'b'.
When compiled with webpack, there are no eslint errors.
When running in the browser, the console doesn't even log any errors.
The only way I know something is wrong is nothing is being displayed on the screen.
Weirdly enough, if i remove the 'var b = 1', ESLint will give me an error saying b is undefined.
Here is my eslint config; nothing special
{
"parser":"babel-eslint",
"plugins":[
"react"
],
"rules":{ },
"extends":["eslint:recommended", "plugin:react/recommended"]
}
What is the problem here? And how can I configure ESLint to catch errors like this in the future?
Thanks
The rule you are looking for is no-use-before-define:
This rule will warn when it encounters a reference to an identifier that has not yet been declared.
You are using the recommended configuration - in which that rule is not enabled. To use it, you will need to enable it explicitly:
{
"parser":"babel-eslint",
"plugins":[
"react"
],
"rules":{
"no-use-before-define": "error"
},
"extends":["eslint:recommended", "plugin:react/recommended"]
}

Can not find the native method in js

I created CalendarManager class in ios native module:
#implementation CalendarManager
RCT_EXPORT_MODULE(#"CalendarManager");
RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location) {
RCTLogInfo(#"Pretending to create an event %# at %#", name, location);
}
#end
and use it in js module :
componentWillMount() {
let CalendarManager = NativeModules.CalendarManager;
console.log(CalendarManager);
CalendarManager.addEvent('Birthday Party', '4 private drive, surrey');
}
then I encountered error: Can not read property 'add Event' of undefined. obviously this error told me that CalendarManager hasn't been imported.
Anything I did wrong ?
Parameter question. it works when I remove RCT_EXPORT_MODULE's parameter, or change parameter #"CalendarManager" to CalendarManager.

ESLint like globals in TSLint

I'm using device plugin from cordova so I have a line like this let model = device.model || ""; which causes Cannot find name 'device'. error. I think with ESLint I would need to do
"eslintConfig": {
"globals": {
"device": true
}
}
but what is the TSLint counterpart of that?
I believe the Cannot find name 'device'. error is generated by the TypeScript compiler, not by TSLint. To solve the problem of missing the global device variable you can write a type definition file. By convention this file is named globals.d.ts.
In it, put the following code:
declare let device: Device;
interface Device {
func: () => void;
prop: string;
}
Replace func and prop with the functions and properties you expect the device variable to have.

Resources