warning on emitDecoratorMetadata for interface in esnext
See original GitHub issueTypeScript Version: 2.4.2
Code (using Angular 4)
// other-file.ts
export interface MyInterface { a: string }
// my-class.ts
import { Input } from '@angular/core'
import { MyInterface } from './otherFile'
class MyClass {
@Input() myi: MyInterface;
}
tsconfig.json
{
"compilerOptions": {
...
"target": "es2017",
"module": "esnext",
"emitDecoratorMetadata": true,
...
}
}
Expected behavior: Working, no errors. I’d expect no type information emitted for interfaces, as they’re only a Typescript compile construct.
Actual behavior:
Although this isn’t a bug per se, TypeScript generates a decorator for type information, referencing MyInterface from otherFile
. Only…this interface doesn’t exist runtime. So bundlers (webpack in my case) produce a warning for this (something like otherFile doesn't export MyInterface
). You can workaround this by creating a local type in my-class.ts
. Or just accept warnings.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:21 (8 by maintainers)
Top Results From Across the Web
Experimental decorators warning in TypeScript compilation
I've to add the following in the settings.json file of vscode to remove the warning. "javascript.implicitProjectConfig.
Read more >TSConfig Reference - Docs on every TSConfig option
An error occurs if any of the files can't be found. This is useful when you only have a small number of files...
Read more >TypeScript errors and how to fix them
Interfaces are structures that define the public contract. ... the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
Read more >type-graphql/Lobby - Gitter
is it possible to add interface to @InputType like object type here ... I have both emitDecoratorMetadata , experimentalDecorators and module: "esnext" in ......
Read more >Help prompts for different compilers
--emitDecoratorMetadata Enables experimental support for emitting type ... are deprecated exported-private-dependencies warn public interface leaks type ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@aluanhaddad Guesses about directions (with which I partly disagree btw) for Angular doesn’t affect that this is an issue with Typescript today, not ngc, not in the future.
Btw, Angular 2 uses this pattern quite a lot, e.g. to detect constructor parameter types. For interface types, it expects the developer to add an extra
@Inject
decorator to indicate the required concrete class or injection token, but for class types, there’s enough information in the constructor parameter metadata to configure the dependency injector.I’ve just tripped across this same issue when trying to use the
transpileOnly: true
option in thets-loader
webpack loader. The warnings about the bogus interface imports are problematic, but the generated runtime test code doesn’t seem to be equivalent for non-interface types.