i have typescript declaration file looks following:
/// <reference types="node" /> declare namespace foo { interface bar { } } declare const foo: foo.bar; export = foo;
this compiles fine ts 2.0/2.2. however, if namespace contains class
whatsoever - e.g. changing bar
class, adding class bam
, etc. - typescript throws error ts2300: duplicate identifier 'foo'.
, 2 declare lines. goal of code written take advantage of declaration merging in typescript, , when foo
contains interface
s, code works expected (type
s seem fine include in foo
, too). why declaration merging fail if foo
contains class
es?
this because class
concrete. namespace
behaves differently when contains types or contains code.
when contains code, emit value. i.e. namespace x
becomes var x
.
when not contain code, no code emitted.
that's why when contains class, emit var foo
conflict const foo
.
https://www.typescriptlang.org/docs/handbook/declaration-merging.html
Comments
Post a Comment