angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

use local share library will get error : Two different types with this name exist, but they are unrelated. #8211

Closed lichunbin814 closed 5 years ago

lichunbin814 commented 7 years ago

Bug Report or Feature Request (mark with an x)

- [ ] feature request

Versions.

@angular/cli: 1.4.4 node: 6.11.2 os: darwin x64 macOS

Repro steps.

folder structure

I add my share library(shared-layout) by angular Cli from local to my node_module, then I use the declaration of Route in my_project from my_share_libary, it will get some error about Type 'Route' is not assignable to type 'Route'. Two different types with this name exist, but they are unrelated.

npm i ../shared-layout


/* shared-layout */
import { Route } from '@angular/router';

export interface LayoutRoute extends Route {
        data?: LayoutRouteData;
        children?: LayoutRoute[];
}

export interface LayoutRouteData {
    someProperty?: {
        someValue : number;
    };
}

/* my_project */
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LayoutRoute } from 'shared-layout/src/shared/layout';

const routes: LayoutRoute[] = [
  { path: 'item', component: ItemComponent },
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})
export class AppRoutingModule { }

The log given by the failure.

[ts]
Argument of type 'LayoutRoute[]' is not assignable to parameter of type 'Route[]'.
  Type 'LayoutRoute' is not assignable to type 'Route'.
    Types of property 'matcher' are incompatible.
      Type 'UrlMatcher' is not assignable to type 'UrlMatcher'. Two different types with this name exist, but they are unrelated.
        Types of parameters 'route' and 'route' are incompatible.
          Type 'Route' is not assignable to type 'Route'. Two different types with this name exist, but they are unrelated.
            Types of property 'matcher' are incompatible.
              Type 'UrlMatcher' is not assignable to type 'UrlMatcher'. Two different types with this name exist, but they are unrelated.
                Types of parameters 'route' and 'route' are incompatible.
                  Type 'Route' is not assignable to type 'Route'. Two different types with this name exist, but they are unrelated.
                    Types of property 'matcher' are incompatible.
                      Type 'UrlMatcher' is not assignable to type 'UrlMatcher'. Two different types with this name exist, but they are unrelated.

Desired functionality.

I want to avoid error from my_proejct when I use file by locale shared library(shared-layout)

Type 'Route' is not assignable to type 'Route'. Two different types with this name exist, but they are unrelated.

Mention any other details that might be useful.

https://github.com/lichunbin814/TestAngularShareLibary/tree/master

Thanks for your help!!!!

mgechev commented 5 years ago

Are you still able to reproduce this issue with the latest version?

mgechev commented 5 years ago

Closing it due to inactivity. If the problem is still reproducible with the latest CLI, please open a new issue following the template and sharing a minimal demo where we can reproduce it. Thank you! :)

angular-automatic-lock-bot[bot] commented 5 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.