Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am making a timer which goes 5:00, 4:59...0:00.Getting many errors while using defer,
1.Property 'pipe' does not exist on type 'void' at pipe(switchMap...
2.Expected 1 arguments, but got 2. at takeWhile
3., expected in few places in ngOnInit
4.A 'this' parameter must be the first parameter at !this.duration
5.No overload matches this call. The last overload gave the following error. Argument of type '{ throw: Error; }' is not assignable to parameter of type 'OperatorFunction<unknown, unknown="">'. Object literal may only specify known properties, and 'throw' does not exist in type 'OperatorFunction<unknown, unknown="">'.

What I have tried:

time$ = timer(0, 1000).pipe(
  defer(of(this.duration)).pipe(switchMap(duration => timer(0, 1000).pipe(map(n => duration - n)),
  takeWhile(n => n >0),
  ngOnInit(): void {
    if (!this.duration) {
      throw new Error('duration is required')

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900