Skip to content

No error about missed "declare" modifier for a top level class inside d.ts #22187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bashor opened this issue Feb 26, 2018 · 5 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@bashor
Copy link

bashor commented Feb 26, 2018

TypeScript Version: 2.7.2

Search Terms: missed declare modifier for a top level class inside d.ts

Code

de.d.ts

export class Foo {
}

test.ts

import { Foo } from "./de";
new Foo()

Expected behavior:
Compiler error, like:
error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file.

Actual behavior
Code is compiled successfully

Related Issues:
#1940

@ghost ghost added the Working as Intended The behavior described is the intended behavior; this is not a bug label Feb 26, 2018
@ghost
Copy link

ghost commented Feb 26, 2018

Since it's in a module in a .d.ts file, declare is optional.

@bashor
Copy link
Author

bashor commented Feb 26, 2018

@Andy-MS where can I read exact rules?

@ghost
Copy link

ghost commented Feb 26, 2018

We don't currently have an up-to-date spec, but any information would be here: http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html

@bashor
Copy link
Author

bashor commented Feb 26, 2018

@Andy-MS, thank you!

Honestly, I didn't find rules about when declare is required and when it's optional. But I've seen that all/most examples omit it when use export modifier.

@bashor
Copy link
Author

bashor commented Feb 26, 2018

@Andy-MS so, should I or you close the issue?

@ghost ghost closed this as completed Feb 26, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

1 participant