question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

warning on emitDecoratorMetadata for interface in esnext

See original GitHub issue

TypeScript 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:open
  • Created 6 years ago
  • Reactions:8
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
staekecommented, Oct 24, 2017

@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.

3reactions
RoystonScommented, Oct 16, 2017

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 the ts-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found