Warnings when using an exported interface in a class
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.
This issue is very annoying. Could you please fix it?
Also waiting this issue to be fixed since a long time..
If you extend an interface the warning remains when you split the interfaces in files

This is getting more attention from users than it should, and less attention from maintainers as I see the dates. Anyway, I come here not to complain (since I know the problem is hard), but to provide a valid workaround.
Our team uses a lot of interfaces. But also a lot of barrels (those index files where you simply re-export public stuff). A workaround that is working perfectly for us is using explicit re-exports, i.e:
Instead of using export * from './file-with-interfaces'; in that index.ts, we do export { SomeClass, SomeType, AnInterface1, AnInterface2 } from './file-with-interfaces';
Later using import { SomeClass, AnInterface1, OtherClass } from './the-folder-with-barrel'; works in the app and shows no warnings. I expect this may help some sorrowful souls ;).
PS: we have 62 interfaces and 0 warnings with this method ;)
I made the same suggestion as @ShadowManu just above and got 3 negative votes - it 'd be nice if you explained your reasons :+1:
@anodynos Fragmenting your code into double the number of files to use an Angular-ideomatic OpaqueToken is sub-optimal. As I mentioned, I come from the Java world and am fairly used to the "one file, one interface" style, but in this case it really feels like the wrong thing to do. (And from a language perspective, it should just work).
Vanilla ES6/ES7 rules!!!
** ducks **
@anodynos there's a couple of differences though. 1) you're not forced to put interfaces aside. Just put them where you deem necessary. 2) The barrel with explicit re-exports is somehow (yeah, I don't get the particular reason) the one making the warnings go away.
@anodynos @ShadowManu The solutions you suggest don't solve the problem, they are just workarounds:
- @anodynos I do want to keep the OpaqueToken and interface in the same file;
- @ShadowManu I do not want to be forced to use barrels. As it was stated by @wulfsberg , it should just work from a language perspective and I think this is the main reason why you are getting thumbs down. Personally, I prefer getting the warning messages than adopting any of those two workarounds.
Thanks @JulienBroi - some some comments:
-
You dont need the
OpaqueToken&IOpaqueTokenor whatever in the same file - you can have anopaque-token-interfaces.tsoropaque-token-types.tsand stick all the interface & type related stuff in there. -
What wrong with barrels?
I don't need it, but I want it, the language allows it, and Angular recommends it. Insisting that I have to do it in another way because of a bug is not a good solution.
It is a workaround and shouldn't be needed. But for those desperate, there's something that can be done in the meantime. Reverting is later as simple as deleting the files and following the broken imports.
Could a maintainer lock this issue? I'm getting my inbox spammed and none of these comments are helpful.
@MazeChaZer All you need to do is to click on the "Unsubscribe" button above on the side.
@catull I would like to get notified when this issue is resolved
For the record, the corresponding issue in webpack is webpack/webpack#2977.
As @hccampos explains there, it touches classes with decorators (annotations):
classes that contain decorators and are using an interface imported from another file trigger the warning. While everything works normally, it would be nice to get rid of the warnings.
Personally I can say it is actually only for the class of a class member annotated with @Input that I see the problem, it is not because of the class itself:
@Input() component: IComponentRow;
will trigger:
WARNING in ./src/app/features/cockpit/workspaces/petals-content/petals-component-view/petals-component-overview/petals-component-overview.component.ts
46:50-63 "export 'IComponentRow' was not found in '../../../state/components/component.interface'
The problem is not because of webpack but most certainly because of something typescript/decorators related (as explained by @sokra: https://github.com/webpack/webpack/issues/2977#issuecomment-245887841). The interface is referenced in the javascript code generated by typescript and thus webpack can't find it (since they have no real existence in the javascript realm).
@filipesilva so I think the problem is coming from typescript itself.
I have a similar situation. I have multiple interfaces in the same file, all exported. From other files I import those and get a warning that it cannot find them. If I split each interface to its own file, the warning goes away.
Sometimes I have interfaces and classes in the same file, same result when importing the interfaces.
368:57-64 "export 'IConfig' was not found in '../models/app-insights'
export interface IAppInsights {
// ...
}
import { IConfig } from '../models/app-insights';
// ...
Things that worked:
- split each interface to its own file
- make them abstract classes
VS Code is happy with this. VS Code can find the import, can navigate to the definition. So it seems to be OK using TypeScript ... but the compiler is not.
cc @alexeagle as an FYI
Ths appears to be a TypeScript thing. ?
we changed our tsconfig.js module from es6 to commonjs and warnings were gone, based on generated code I'm not sure whats different.
Input decorator code with es6: __decorate([ webpack_require.i(WEBPACK_IMPORTED_MODULE_0__angular_core["Input"])(), __metadata('design:type', (typeof (_a = typeof WEBPACK_IMPORTED_MODULE_1__models_user_info["UserInfo"] !== 'undefined' && WEBPACK_IMPORTED_MODULE_1__models_user_info["UserInfo"]) === 'function' && _a) || Object) ], HeaderComponent.prototype, "user", void 0);
Input decorator code with commonjs: __decorate([ core_1.Input(), __metadata('design:type', (typeof (_a = typeof user_info_1.UserInfo !== 'undefined' && user_info_1.UserInfo) === 'function' && _a) || Object) ], HeaderComponent.prototype, "user", void 0);
We need a better way to isolate which layer is causing the problem - it seems like angular CLI magic is making this difficult. Perhaps a minimal repro without the CLI would help?
@alexeagle I dont have a minimal repro, though I will try to find a better one.
In the meantime, if you clone this repo and branch, run npm i, then run ng b you will see the issues I mentioned.
https://github.com/projectkudu/AzureFunctionsPortal/tree/upgrade-angular-v4