#Module augmentation without hiding the rest of the module

9 messages · Page 1 of 1 (latest)

fallen sinew
#

Using this sample code in src/types/@angular/router/index.d.ts:

type MyRoutes = 'a' | 'b'

declare module '@angular/router' {
  export declare interface Route {
    path: MyRoutes,
    foo: string, // Just for testing
  }
}

Typescript successfully detects that Route.path should now be of type MyRoutes. However, it also hides the entire rest of the module. (in the image below, Routes and providedRoute should still be found)

How could I augment only this one interface w/o hiding the rest of the module?

Using typescript 5.3.3

river heart
#

Do you need declare module? Because without that, the interfaces would merge I think

chrome dawn
#

@fallen sinew Is src/types configured as typeRoots in TSConfig? Because I think you don't want that for declration merging.

#

typeRoots is for setting up equivalent folders to node_modules/@types.

#

If so, I would try moving that file into something that's a normal source folder.

fallen sinew
fallen sinew
chrome dawn
#

The other thing I'd try is moving type MyRoutes inside the declare module block

#

I know it matters if you have imports or exports outside of the declare module; I'm not sure if things like declaring aliases outside matters.