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.

No error when namespace export is used before assigned

See original GitHub issue

TypeScript Version: 2.6.2

Search Terms: namespace decorator same class

Code

@C1.Decorator
export class C1{ }
export namespace C1 { 
  export function Decorator<T>(target: T) { }
}
@C1.Decorator
@C2.Decorator
export class C2 { }

export namespace C2 { 
  export function Decorator<T>(target: T) { }
}

Expected behavior: if this is not a feature, decorator should be defined at runtime, or it should provide some warning or error during compilation?

Actual behavior: decorator from namespace C1 used on class C1 is undefined, decorator from C1 is defined when used on C2, decorator from C2 is undefined

Playground Link: https://www.typescriptlang.org/play/index.html#src=%40C1.Decorator export class C1{ } export namespace C1 { export function Decorator<T>(target%3A T) { } } %40C1.Decorator %40C2.Decorator export class C2 { } export namespace C2 { export function Decorator<T>(target%3A T) { } }

Related Issues: I did not find any

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
andy-mscommented, Jan 22, 2018

It looks like the general problem is that we don’t give you a used-before-assigned error for a variable in a namespace.

console.log(N.x);
namespace N {
    export const x = 0;
}

It seems like we could do this, so marking as a bug for now.

0reactions
sandersncommented, Aug 15, 2018

Now that functions support expando properties in TS (and have for some time in JS), the same bug repros there:

f.p // should have an error here
function f() {}
f.p = { x: "" };
f.p // ok
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript error "An export assignment cannot be used in a ...
I found that I could combine export = syntax with namespace to export types from the interface. export = is necessary (as far...
Read more >
Fixing the "Cannot Use Namespace as a Type" Error in ...
To fix this error, use an export assignment to specify a default export for the namespace, like this: car.d.ts declare module 'car' {...
Read more >
Documentation - Namespaces - TypeScript
This post outlines the various ways to organize your code using namespaces (previously “internal modules”) in TypeScript. As we alluded in our note...
Read more >
export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the ......
Read more >
Google TypeScript Style Guide
Identifiers should not generally use $ , except when aligning with naming ... Some libraries might commonly use a namespace import prefix that...
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