Reputation: 47
I have this piece of code which gives me an error with typescript.
firebaseAdmin.firestore().collection('arenas').get()
.then((snapshot: any) => {
snapshot.forEach((element: any) => {
scraptIt(firebaseFunctions.config().sports.url + element.data().url, {
sports: {
listItem: '.LSport',
data: ['b']
}
}).then((data: any) => {
sportsArray.push(data)
sportsArray = [...new Set(data)]
}).catch((err: any) => { res.send(err); console.log(err) })
})
}).catch((err: any) => { res.send(err); console.log(err) })
I'm receiving the following error
Argument of type '{ sports: { listItem: string; data: string[]; }; }' is not assignable to parameter of type 'ScrapeOptions'. Property 'sports' is incompatible with index signature. Type '{ listItem: string; data: string[]; }' is not assignable to type 'string | ScrapeOptionList | ScrapeOptionElement'. Type '{ listItem: string; data: string[]; }' has no properties in common with type 'ScrapeOptionElement'.
I'm using this package: Scrape-It
Upvotes: 3
Views: 1674
Reputation: 5962
you are using the below method signature from Scrapeit library
declare function scrapeIt<T>(url: string | object, opts:scrapeIt.ScrapeOptions): Promise<T>;
which means the second parameter for the method scraptIt()
should be of type ScrapeOptions
. If you observe the definition of the interface ScrapeOptions
carefully you can see that it accepts the below format as input
export interface ScrapeOptions {
[key: string]: string | ScrapeOptionList | ScrapeOptionElement;
}
The ScrapeOptionList
interface is defined as
export interface ScrapeOptionList {
listItem: string;
data: ScrapeOptions;
}
In your code you are passing the second parameter as below
scraptIt(firebaseFunctions.config().sports.url + element.data().url, {
sports: {
listItem: '.LSport',
data: ['b'] // here is the issue
}
})
the value for data
should be of type ScrapeOptions
as per the definition . Hence you need to change it to either a simple string or type of ScrapeOptionList
or type of ScrapeOptionElement
.
you can try to change it to data: 'b'
as per your need
Or set data
property value as type of ScrapeOptionList
or ScrapeOptionElement
.
a sample format to be used should look like below -- (Not sure why are you using data:['b']
) . In my opinion it should be data : { "somekey" : 'b'}
pages: {
listItem: "li.page"
, name: "pages"
, data: {
title: "a"
, url: {
selector: "a"
, attr: "href"
}
}
}
Upvotes: 3