angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Warnings when using an exported interface in a class

Open Maistho opened this issue 10 years ago • 140 comments

1. OS

Arch Linux

Linux maistho-laptop 4.7.2-1-ARCH #1 SMP PREEMPT Sat Aug 20 23:02:56 CEST 2016 x86_64 GNU/Linux

2. Versions

angular-cli: 1.0.0-beta.11-webpack.8
node: 6.5.0
os: linux x64

3. Repro steps

I started a new repository, and added a new empty service, with an exported interface.

Complete changes, and a repo to pull and see the issue, can be found here:

https://github.com/Maistho/angular-cli-input-issue/commit/e5c483081bfd7af3dafd0db074179b3090668e27

After running ng build, I get two warnings in the Terminal

4. The log given by the failure

Hash: 354e709ba2cf588db59a                                                                                                                                                                                          
Version: webpack 2.1.0-beta.21
Time: 11161ms
            Asset       Size  Chunks             Chunk Names
   main.bundle.js    2.51 MB    0, 2  [emitted]  main
 styles.bundle.js    10.2 kB    1, 2  [emitted]  styles
        inline.js    5.53 kB       2  [emitted]  inline
         main.map     3.1 MB    0, 2  [emitted]  main
       styles.map    14.1 kB    1, 2  [emitted]  styles
       inline.map    5.59 kB       2  [emitted]  inline
       index.html  489 bytes          [emitted]  
assets/.npmignore    0 bytes          [emitted]  
chunk    {0} main.bundle.js, main.map (main) 2.46 MB {1} [initial] [rendered]
chunk    {1} styles.bundle.js, styles.map (styles) 9.96 kB {2} [initial] [rendered]
chunk    {2} inline.js, inline.map (inline) 0 bytes [entry] [rendered]

WARNING in ./src/app/app.component.ts
18:55 export 'TestInterface' was not found in './test.service'

WARNING in ./src/app/app.component.ts
18:88 export 'TestInterface' was not found in './test.service'
Child html-webpack-plugin for "index.html":
         Asset     Size  Chunks       Chunk Names
    index.html  2.82 kB       0       
    chunk    {0} index.html 357 bytes [entry] [rendered]

5. Mention any other details that might be useful.

I could not reproduce the issue without adding the @Input() to the class member.

Compiling with tsc does not produce any warnings.

Maistho avatar Sep 09 '16 17:09 Maistho

@th0r why don't you try it out? I think you'll find that the result is empty, despite your expectations. Keep in mind you are using the class here as a type annotation only, and more importantly you are not explicitly re-exporting it. From the outside all that is exported is the interface which consists of type annotations and nothing more.

mischkl avatar May 24 '17 11:05 mischkl

@mischkl I'm sorry! You're right - just tried to extract them into separate files again and warnings have disappeared. Seems like I did something wrong first time 🤔

th0r avatar May 24 '17 11:05 th0r

@filipesilva is there a typescript issue for this that can be referenced by this issue for future tracking if it gets fixed?

zakhenry avatar May 24 '17 12:05 zakhenry

@zakhenry not that I know of, no.

filipesilva avatar May 24 '17 21:05 filipesilva

~~Is there a reason why these warnings fail execution in the browser when its just warnings and not errors? As mentioned by someone in [email protected] it seemed no showstopper for development but as of [email protected] it halts development completely when it happens. My team is in the progress of migrating an app with 150+ components and suddenly this issue appeared for us. I'm still goofing around trying to find workarounds. It seems to have appeared completely random after having migrated roughly 30 components..~~ EDIT: Upgrading first helps.. had a specific version entered in package.json facepalm

So far I've found that any kind of union type on affected decorated properties will remove the warning, e.g.

@Input() someProp:MyMagicalInterface

will result in a warning while

@Input() someProp:MyMagicalInterface | undefined

will work. And to get completely funky

@Input() someProp:MyMagicalInterface | MyMagicalInterface

does work also. ¯_(ツ)_/¯

reppners avatar May 26 '17 23:05 reppners

for whatever it's worth ... when you change the module in the tsconfig to "commonjs" the error goes away. This may not work for most situations, in mine it does because I am using a core module that is compiled outside of the cli project (with ngc) and later linked into it.

axtho avatar Jun 10 '17 05:06 axtho

// ./src/app/wx.d.ts
export declare function config(): void;
// ./src/app/app.component.ts
import * as wx from './wx.d';

// using
wx.config();

ng serve throw Module build failed: Error: Debug Failure. False expression: Output generation failed.

cipchk avatar Jun 10 '17 14:06 cipchk

Changing tsconfig module to "commonjs" fixed the warnings for me. Previously it was set to "es2015"

strake7 avatar Jun 21 '17 16:06 strake7

is there a way to just silence that warning?

remmeier avatar Jul 07 '17 07:07 remmeier

@remmeier see the comment a few above - you can suppress the warning simply by making the type a union of itself. The same type safety is achieved, and the warning goes away. It is by no means a fix, but at least you can continue developing

zakhenry avatar Jul 07 '17 08:07 zakhenry

The issue still exists, why is this closed?

RenaldasK avatar Jul 08 '17 16:07 RenaldasK

@RenaldasK there is long explanation (shortly - it is the limitation which currently cannot be solved) https://github.com/angular/angular-cli/issues/2034#issuecomment-302666897

Try to rewrite interfaces to classes if possible (this works for me). Or one of the proposed solutions above (i did not try any of them).

tytskyi avatar Jul 08 '17 22:07 tytskyi

Aside from the console warnings, is there any actual reason to avoid this issue?

MattMorrisDev avatar Jul 08 '17 22:07 MattMorrisDev

All of the solutions above feel like a hacks, and putting a single line interface in its own file seems like a waste of time...

RenaldasK avatar Jul 10 '17 12:07 RenaldasK

Having the same issue with a scenario like this:

export class Something { ... }
export type SomethingKey = Pick<Something , 'keyPropertyName'>;

in one file. However when I add another interface, class or type to that file, the interface is resolved perfectly fine. This seem to be only the issue with the Pick<..> type. It works, compiles, transpiles, it only gives a warning in the CLI...

bickycheese avatar Jul 19 '17 06:07 bickycheese

@filipesilva Thanks for looking into the problem in detail. Easiest workaround I have found is to declare a local alias type in the component file for the imported type when needed in an @Input(). So for your example, rather than:

import {TestInterface} from ...
...
@Input() test: TestInterface

do a

import {TestInterface} from ...
type TestInterfaceAliasHack = TestInterface;
...
@Input() test: TestInterfaceAliasHack

mmc41 avatar Jul 23 '17 17:07 mmc41

This is really annoying. Is there a real fix and not simply temporary workarounds?

Ks89 avatar Jul 29 '17 06:07 Ks89

This issue's very Annoying !

elvisbegovic avatar Jul 29 '17 10:07 elvisbegovic

For the time being just a flag to silence the warnings would be great as everything works perfectly fine regardless of the warnings.

remmeier avatar Jul 29 '17 10:07 remmeier

They said working on it, i have the same issue just have to wait or work with a work-around if possible.

ndcunningham avatar Aug 01 '17 18:08 ndcunningham