Home > OS >  TS2322: not the good type
TS2322: not the good type

Time:11-22

I followed an msal, angular tutorial

https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-angular-auth-code

This part of the code seem to be the problem

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    initialNavigation: !isIframe ? 'enabled' : 'disabled'
  })],
  exports: [RouterModule]
})

When i do

npm start

I get this error

TS2322: Type '"disabled" | "en abled"' is not assignable to type 'InitialNavigation | undefined'. Type '"enabled"' is not assignable to type 'InitialNavigation | undefined'.

When i click on initialNavigation, i see

/**
 * One of `enabled`, `enabledBlocking`, `enabledNonBlocking` or `disabled`.
 * When set to `enabled` or `enabledBlocking`, the initial navigation starts before the root
 * component is created. The bootstrap is blocked until the initial navigation is complete. This
 * value is required for [server-side rendering](guide/universal) to work. When set to
 * `enabledNonBlocking`, the initial navigation starts after the root component has been created.
 * The bootstrap is not blocked on the completion of the initial navigation. When set to
 * `disabled`, the initial navigation is not performed. The location listener is set up before the
 * root component gets created. Use if there is a reason to have more control over when the router
 * starts its initial navigation due to some complex initialization logic.
 */
initialNavigation?: InitialNavigation;

CodePudding user response:

According to Angular docs, type InitialNavigation can be assigned one of the following values: 'disabled', 'enabledBlocking', or 'enabledNonBlocking'.

type InitialNavigation = 'disabled' | 'enabledBlocking' | 'enabledNonBlocking';

Where enabledNonBlocking is the default behaviour.

  • Related