TypeScript
TypeScript copied to clipboard
No error report on duplicated function/class declaration
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play
π» Code
declare function foo() : any
declare class foo {
test() : any
}
π Actual behavior
no error report
π Expected behavior
I think it should report error because we have duplicated 'foo' defintion.
https://www.typescriptlang.org/docs/handbook/declaration-merging.html
βitβs a feature, not a bugβ π
This is the syntax you would use to describe an object which is callable both with and without new, which is a thing that people do in JS sometimes.
which is a thing that people do in JS sometimes.
@RyanCavanaugh Your comment is roughly 2 weeks to early.
this is confused, because it report errors if without 'declare' keyword:
function foo() : any {}
// Class declaration cannot implement overload list for 'foo'.(2813)
class foo {
test() : any {}
}
so can I just simpliy assume that the declaration with 'declare' is like something in header file for js but not for ts?
the declaration with 'declare' is like something in header file for js but not for ts?
Yes. It basically tells TypeScript that this will exist at runtime.
clear now, close this issue, thanks everyone for clarification