Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MegaMenu doesn't compile with TypeScript 2.4 #3640

Closed
Cito opened this issue Aug 10, 2017 · 2 comments
Closed

MegaMenu doesn't compile with TypeScript 2.4 #3640

Cito opened this issue Aug 10, 2017 · 2 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@Cito
Copy link
Contributor

Cito commented Aug 10, 2017

I'm submitting a ...

[X] bug report

Test case

You can use the following demo app as test case:
https://github.com/ova2/angular-development-with-primeng/tree/master/chapter7/megamenu

Current behavior
If you run the showcase for the MegaMenu with TypeScript 2.4 or run the demo app linked above, you will get a compilation error like

 Type '{ label: string; items: { label: string; }[]; }[]' has no properties in common with type 'MenuItem'.

Expected behavior
There should be no compilation error, as when compiling with TypeScript 2.3.

Minimal reproduction of the problem with instructions

  • Install the above app

  • or install the current master of PrimeNG and change the requirements in package.json to Angular 4.3, Angular-Cli 1.3, TypeScript 2.4 (lower Angular/Cli versions require TypeScript 2.3, so you need to test with Angular 4.3 and Cli 1.3)

  • Run npm install and npm start and check the MegaMenu

  • Angular version: 4.3.3

  • PrimeNG version: 4.1.2

  • Browser: all

  • Language: TypeScript 2.4

  • Node (for AoT issues): 8.1.4

  • Analysis of the problem:

In the MenuItem interface, the items property is defined as of type MenuItem[]. But in the MegaMenu, you can have arrays of arrays of MenuItems as items, not just arrays of MenuItems.

In TypeScript 2.4, it’s now an error to assign anything to a weak type when there’s no overlap in properties (see here).

Note that in the MenuItem interface all properties are marked as optional. Therefore, this is considered a "weak type".

  • Proposed solution:

The items property in the MenutItem interface should be defined as follows:

items?: MenuItem[]|MenuItem[][];
@cagataycivici cagataycivici self-assigned this Oct 19, 2017
@cagataycivici cagataycivici added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working Status: Pending Review Issue or pull request is being reviewed by Core Team labels Oct 19, 2017
@cagataycivici cagataycivici added this to the 4.2.3 milestone Oct 19, 2017
@Guoye
Copy link

Guoye commented Oct 23, 2017

发现 version: 4.2.2 也存在相同的问题,以下是showcase的编译错误:

Minimal reproduction of the problem with instructions

Angular version: 4.4.4

PrimeNG version: 4.2.2

Analysis of the problem:

Failed to compile.

primeng/src/app/components/common/messageservice.ts (21,37): Type 'Message[]' has no properties in common with type 'Message'.

primeng/src/app/showcase/components/megamenu/megamenudemo.ts (12,9):Type '{ label: string; icon: string; items: { label: string; items: { label: string; }[]; }[][]; }[]' is not assignable to type 'MenuItem[]' ....

@cagataycivici cagataycivici changed the title MegaMenu showcase doesn't compile with TypeScript 2.4 MegaMenu doesn't compile with TypeScript 2.4 Oct 24, 2017
@cagataycivici cagataycivici added confirmed and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Oct 24, 2017
@corvinrok
Copy link

Why is this not included in the latest 5.0.0-rc release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

4 participants