Property 'get' in type 'ToastInjector' is not assignable to the same property in base type 'Injector'

3.9k Views Asked by At

error TS2416: Property 'get' in type 'ToastInjector' is not assignable to the same property in base type 'Injector'.

Type '(token: any, notFoundValue?: T, flags?: InjectFlags) => ToastPackage | T' is not assignable to type '{ (token: ProviderToken, notFoundValue: undefined, options: InjectOptions & { optional?: false; }): T; (token: ProviderToken, notFoundValue: null, options: InjectOptions): T; (token: ProviderToken<...>, notFoundValue?: T, options?: InjectOptions | InjectFlags): T; (token: ProviderToken<...>, notFou...'.

Types of parameters 'flags' and 'options' are incompatible.
  Type 'InjectOptions & { optional?: false; }' is not assignable to type 'InjectFlags'.

toast-injector.ts

import {Injector, InjectFlags} from '@angular/core’;

import { ToastPackage } from './toast-config';



export class ToastRef<T> {

export class ToastInjector implements Injector {

  constructor (

    private _toastPck: ToastPackage,

    private _parntInjtr: Injector

  ) {}


  //eslint-disable-next-line

  get<T> (token: any, notFoundValue?: T, flags?: InjectFlags): T | ToastPackage {

    if (token === ToastPackage) {

      return this. _toastPck;

    }

    return this._parntInjtr.get<T> (token, notFoundValue, flags);

  }

}

The issue is coming in angular 16 after upgradation.Actual issue causing at "get". Any suggestion how to handle this get.

enter image description here

1

There are 1 best solutions below

1
barthony On

I had the same issue updating angular from 14 to 15 and could be able to fixed it

  • By adding "skipLibCheck":true in angularCompilerOptions section of the tsconfig file

or

  • By updating ngx-toastr to version 16.0.0