No overload matches this call. Overload 1 of 5, '(next: null | undefined, error: (error: any) => void, complete?: (() => void) | undefined): Subscript - angular11

I'm getting following error message while accessing assigning response from a variable.
Code:
Error:
No overload matches this call.
Overload 1 of 5, '(next: null | undefined, error: (error: any) => void, complete?: (() => void) | undefined): Subscription', gave the following error.
Argument of type '(response: Employee[]) => void' is not assignable to parameter of type 'null | undefined'.
Type '(response: Employee[]) => void' is not assignable to type 'null'.
Overload 2 of 5, '(next?: ((value: Employee) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined): Subscription', gave the following error.
Argument of type '(response: Employee[]) => void' is not assignable to parameter of type '(value: Employee) => void'.
Types of parameters 'response' and 'value' are incompatible.
Type 'Employee' is missing the following properties from type 'Employee[]': length, pop, push, concat, and 26 more.ts(2769)

I found the mistake in this. Service method return type was mismatch with this one.

Related

Selectors No overload matches this call

Here's my selector.ts
export interface ITestState {
value: number;
}
export interface IReduxState {
test: ITestState;
}
export const selectTest = (state: IReduxState) => state.test;
export const selectTestValue = createSelector(
selectTest,
(state: ITestState) => state.value
);
Ïf i try to use it in app.component.ts
Like so
constructor(private store: Store) {
this.vaschal$ = store.select(selectTestValue);
}
I get the following error
No overload matches this call.
Overload 1 of 9, '(mapFn: (state: object) => number): Observable<number>', gave the following error.
Argument of type 'MemoizedSelector<IReduxState, number, DefaultProjectorFn<number>>' is not assignable to parameter of type '(state: object) => number'.
Types of parameters 'state' and 'state' are incompatible.
Property 'test' is missing in type '{}' but required in type 'IReduxState'.
Overload 2 of 9, '(key: never): Observable<never>', gave the following error.
Argument of type 'MemoizedSelector<IReduxState, number, DefaultProjectorFn<number>>' is not assignable to parameter of type 'never'
angular version 11.2.4
What do i do wrong?
You need to inform the Store of the root store state:
constructor(private store: Store<IReduxState>) {
this.vaschal$ = store.select(selectTestValue);
}

Why do I get "expected type Future" error using match statement on Result?

I'm trying to use a function in an external crate, it is supposed to return a Result<T, E> struct as implied by the function's signature:
pub async fn market_metrics(symbols: &[String]) -> Result<Vec<market_metrics::Item>, ApiError>
I'm trying to unpack the Result<T, E> with a match statement as instructed in Rust's documentation, but I am getting this error for some reason:
use tastyworks::market_metrics;
fn main() {
let symbols = &[String::from("AAPL")];
let m = market_metrics(symbols);
match m {
Ok(v) => v,
Err(e) => panic!(e),
}
}
error[E0308]: mismatched types
--> src/main.rs:7:9
|
7 | Ok(v) => v,
| ^^^^^ expected opaque type, found enum `std::result::Result`
|
::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tastyworks-0.13.0/src/lib.rs:79:52
|
79 | pub async fn market_metrics(symbols: &[String]) -> Result<Vec<market_metrics::Item>, ApiError> {
| ------------------------------------------- the `Output` of this `async fn`'s expected opaque type
|
= note: expected opaque type `impl std::future::Future`
found enum `std::result::Result<_, _>`
The dependency in Cargo.toml to use this crate is:
tastyworks = "0.13"
The function you are trying to use is an async so you need to spawn an async task for it or run it in an async context. You need tokio (or another async backend) for it:
use tastyworks::market_metrics;
use tokio;
#[tokio::main]
async fn main() {
let symbols = &[String::from("AAPL")];
let m = market_metrics(symbols).await;
match m {
Ok(v) => v,
Err(e) => panic!(e),
}
}
Check some interesting related answers

Rust - Error when trying to remove struct element from vector

A simple attempt to add print and remove elements from a vector but I'm stuck with this error and couldn't find a solution online, so posting it here.
When I try to remove the item without the type definition it gives me an error to add the type, when I do add the type , i get an error regarding RangeBounds , don't know what it means so might need an explanation on this.
Version 1
use structopt::StructOpt;
#[derive(StructOpt,Debug)]
struct CliArgs {
action: String,
id: String,
}
#[derive(PartialEq,Eq,Debug,Clone)]
struct Item{
id:String,
}
fn main() -> std::result::Result<(),Box<dyn std::error::Error>>{
let args = CliArgs::from_args();
let mut items = vec![];
match args.action.as_str() {
"add" => {
items.push(Item {id:args.id});
println!("Added!");
println!("{:?}",items);
},
"print" => {
println!("{:?}",items);
},
"delete" => {
items.drain(|x| x.id == args.id);
println!("{:?}", items);
}
_ => {
return Err("Invalid Action, actions supported are: add and delete".into());
}
};
Ok(())
}
Version 2:
use structopt::StructOpt;
#[derive(StructOpt,Debug)]
struct CliArgs {
action: String,
id: String,
}
#[derive(PartialEq,Eq,Debug,Clone)]
struct Item{
id:String,
}
fn main() -> std::result::Result<(),Box<dyn std::error::Error>>{
let args = CliArgs::from_args();
let mut items = vec![];
match args.action.as_str() {
"add" => {
items.push(Item {id:args.id});
println!("Added!");
println!("{:?}",items);
},
"print" => {
println!("{:?}",items);
},
"delete" => {
items.drain(|x:Item| x.id == args.id);
println!("{:?}", items);
}
_ => {
return Err("Invalid Action, actions supported are: add and delete".into());
}
};
Ok(())
}
The Errors I get
Version 1:
❯ cargo run
Compiling workit v0.1.0 (/Users/reaper/code/workit)
error[E0282]: type annotations needed
--> src/main.rs:32:26
|
32 | items.drain(|x| x.id == args.id);
| ^ consider giving this closure parameter a type
|
= note: type must be known at this point
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
error: could not compile `workit`.
To learn more, run the command again with --verbose.
Version 2:
❯ cargo run
Compiling workit v0.1.0 (/Users/reaper/code/workit)
error[E0277]: the trait bound `[closure#src/main.rs:32:25: 32:49 args:_]: std::ops::RangeBounds<usize>` is not satisfied
--> src/main.rs:32:19
|
32 | items.drain(|x:Item| x.id == args.id);
| ^^^^^ the trait `std::ops::RangeBounds<usize>` is not implemented for `[closure#src/main.rs:32:25: 32:49 args:_]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `workit`.
To learn more, run the command again with --verbose.

Can't subscribe to results of combineLatest

My app broke when I updated to RxJS 6. I got most of it working but this one method has me stumped.
Previously we had an array of observables being flatMapped and then used combineLatest like this:
const newObservable = myArrayOfObservables
.flatMap(observables => {
return Observable.combineLatest(observables);
});
And I could subscribe to the newObservable and get an array of the latest outputs from all the others.
Now I'm trying to do something like this:
const mergedList$ = chatList$.pipe(
mergeMap(res => {
return combineLatest(res);
}));
This gives me one of those really long and convoluted
Argument of type '(res: Observable<{ $key: string; }>[]) => OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>' is not assignable to parameter of type '(value: Observable<{ $key: string; }>[], index: number) => ObservableInput<{}>'.
Type 'OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>' is not assignable to type 'ObservableInput<{}>'.
Type 'OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>' is not assignable to type 'Iterable<{}>'.
Property '[Symbol.iterator]' is missing in type 'OperatorFunction<{}, [{}, Observable<{ $key: string; }>]>'.
which quite frankly my dyslexia prevents me from parsing.
If I just return res in the above, and then try
const mergeCombo = combineLatest(mergedList$);
now mergeCombo is not an observable. Instead it's a
OperatorFunction<{}, [{}, Observable<{
$key: string;
}>]>
It could be worth noting that my original observables are being emitted by AngularFireObject.snapshotChanges()
You don't show how you imported combineLatest. It sort of looks like you are importing it as an operator, which has been deprecated.
Make sure you import it like so:
import {combineLatest} from "rxjs";
Then your original code should work just fine:
const mergedList$ = chatList$.pipe(
mergeMap(res => combineLatest(res))
);

How do I statically type a response from `window.fetch` with Flow?

I'm window.fetch'ing a response from an JSON API, and I'd like to type check my access to the response. For example:
type Result = {|+text: string, +metadata: {...}|};
type ApiResponse = Response & {|
json: () => Result,
text: null,
|};
const getResult = (): Promise<ApiResponse> => fetch(url);
// access to getResult().then(r => r.json()) is type checked against Result
But Flow fails to type check with:
Error: src/data/fetcher.js:18
v-
18: export type ApiResponse = Response & {|
19: json: () => Promise<Result>,
20:
...:
23: |};
-^ exact type: object type. Inexact type is incompatible with exact type
987: declare function fetch(input: RequestInfo, init?: RequestOptions): Promise<Response>;
^^^^^^^^ Response. See lib: /private/tmp/flow/flowlib_211b7075/bom.js:987
Which I guess makes sense because it can't reconcile fetch's return type of Promise<Response> with getResult's return type of Promise<ApiResponse>.
How can I constrain that the thing getResult is returning is a Promise?
How can I constrain that the thing getResult is returning is a Promise?
Type it as a Promise<Response>
The type for Response.json() already resolves to any, so you can assert it is whatever type you want:
declare class Response {
...
json(): Promise<any>;
...
}
The next question you might have is "How do I let Flow know the type returned upon calling json()?"
Type that as whatever you're expecting. Something like this:
fetch(url)
.then(res => res.json())
.then((obj: Result) => {
// Access your obj here
// (Preferably with some level of checking to make sure
// the API returned a valid object)
})

Resources