Property doesn't exist on type {} - angularfire2

I am trying to get a list of objects from a firebase db using snapshotChanges.
Angular Version: 7.2.0,
Firebase Version: 5.8.1,
RxJS Version: 6.3.3,
AngularFire2: 5.1.1
My code is the following:
this.fbSubs.push(this.db
.collection('availableExercises')
.snapshotChanges()
.pipe(
map(docArray => {
return docArray.map(doc => {
return {
idExercise: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories
};
});
})
)
.subscribe((exercises: Exercise[]) => {
// code...
}, error => {
// code...
}));
When I try to compile this code, I get the following errors:
ERROR in src/app/training/training.service.ts(41,44): error TS2339: Property 'name' does not exist on type '{}'.
src/app/training/training.service.ts(42,48): error TS2339: Property 'duration' does not exist on type '{}'.
src/app/training/training.service.ts(43,48): error TS2339: Property 'calories' does not exist on type '{}'.
I believe the syntax may be outdated from a previous version of RxJS but I can't seem to work out what I need to change.

So I had to slightly change the code around in .pipe.map() to return the data as "Exercise" like so:
.pipe(
map(docArray => {
return docArray.map(doc => {
const data = doc.payload.doc.data() as Exercise;
const idExercise = doc.payload.doc.id;
return {idExercise, ...data};
});
})
)

.pipe(
map(docArray => {
return docArray.map(doc => {
return {
id: doc.payload.doc.id,
...doc.payload.doc.data() as Exercise
};
});
})
)

Related

Using this.skip with cypress-json-failed results in: TypeError: Cannot read properties of undefined (reading 'message')

I am attempting to use a global beforeeach() algorithm defined in support/e2e to filter tests. This code works.
beforeEach(function () {
var testSuite = new Array();
testSuite = (Cypress.env('suites'));
if (!testSuite) {
return;
}
const testName = Cypress.mocha.getRunner().test.fullTitle().toLowerCase();
let matches = testSuite.some((value) => {
return (testName.includes(value))
});
if (!matches) {
this.skip();
}
return;
})
However, when using in conjunction with cypress-failed-log, tests that are skipped because of the prior algorithm are failing with this error:
TypeError: Cannot read properties of undefined (reading 'message')
Because this error occurred during a `after each` hook we are skipping all of the remaining tests.
at Context.onFailed (webpack:///./node_modules/cypress-failed-log/src/index.js:136:0)
This is what my plug in looks like. It works independent of the sorting algorithm and fails with the same message even if I only leave just the failed:required line and remove the code that uses the message object.
on('task', {
failed: require('cypress-failed-log/src/failed')()
,
log(message) {
console.log(message)
return null
},
table(message) {
console.table(message)
return null
}
})

Microsoft Teams TASK module SSO is returning `Definition not found` error

We are getting Definition not found error while calling msTeams.authentication.getAuthToken in #microsoft/teams-js from the task module.
#microsoft/teams-js version - 1.7.0 and 1.11.0
Environment - Desktop and Mobile
return new Observable<any>(subscriber => {
this.teamsService.authentication.getAuthToken({
resources: ['https://graph.microsoft.com/openid',
'https://graph.microsoft.com/user.read.all',
'https://graph.microsoft.com/group.read.all',
'https://graph.microsoft.com/groupmember.read.all'],
successCallback: clientToken => {
subscriber.next({ clientToken, type: this.authType });
subscriber.complete();
},
failureCallback: reason => {
subscriber.error(reason);
}
});
});

Cypress: The 'task' event has not been registered in the plugins file. You must register it before using cy.task()

I am writing the end-to-end tests using Cypress for my web application. In my tests, I am trying to create a task, https://docs.cypress.io/api/commands/task. But it is throwing an error. Here is what I did.
I declared a task in the plugins/index.js file as follow.
module.exports = (on) => {
on("task", {
setTestId(id) {
testId = id;
return null;
},
getTestId() {
return testId;
}
});
};
Then I use the task in the test as follow.
cy.task('setTestId', 7654321);
When I run the tests, I am getting the following error.
The 'task' event has not been registered in the plugins file. You must register it before using cy.task()
As you can see, I tried this solution as well, Cypress task fails and complains that task event has not been registered in the plugins file. It did not work either. What is wrong with my code and how can I fix it?
You're missing some formatting (":" and "=>" and such). Try this:
module.exports = (on) => {
on("task", {
setTestId: (id) => {
testId = id;
return null;
},
getTestId: () => {
return testId;
}
});
};
Set the testId as you did:
cy.task('setTestId', 7654321);
And when you want to retrieve the testId, use:
cy.task('getTestId').then((testId) => {
cy.log(testId)
});

How to fix Type 'AsymmetricMatcher<any>' is not assignable to type '() => void'. in jasmine/jest

I have a object config where I send a function callback to a function.
test('should create a ComponentMockwith the needed config', () => {
const config: MyConfig = {
// more options
myCallback: jasmine.anything()
};
sut.doYourThing(config);
expect(ComponentMock.create).toHaveBeenCalledWith(config);
});
The problem I have is that after an update to the latest jest/jasmine I get this error in myCallback: jasmine.anything():
How to fix Type 'AsymmetricMatcher' is not assignable to type '() => void'. in jasmine/jest
If I ignore that line with #ts-ignore my test keeps working but I want to know why is the linter saying that and how to fix it since I really do not understand it.
I had same issue in my app, I have solved it by mapping troublesome type to any jasmine.anything() as any. Maybe it will solve your problem as well.
test('should create a ComponentMockwith the needed config', () => {
const config: EqListeningPlayerConfig = {
// more options
myCallback: jasmine.anything() as any // < --- here is what solved my issue
};
sut.doYourThing(config);
expect(ComponentMock.create).toHaveBeenCalledWith(config);
});

i get error 'FileProvider' of undefined using record function with nativescript-videorecorder

i need help.
TypeError: Cannot read property 'FileProvider' of undefined
I get that error when i try to record.
Code:
const options: VideoRecorderOptions = {
hd: true,
saveToGallery: true
}
const videorecorder = new VideoRecorder(options)
videorecorder.record().then((data) => {
console.log(data.file)
}).catch((err) => {
console.log(err)
})
It seems to be Android X compatibility issue, the plugin author will have to update the plugin to support {N} 6.x and later.
android.support.v4.content.FileProvider is now androidx.core.content.FileProvider. You may update the code and compile it locally as a workaround.

Resources