Skip to content
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

Do we need to use "declare" for type aliased in d.ts files? #1940

Closed
mpawelski opened this issue Feb 5, 2015 · 4 comments
Closed

Do we need to use "declare" for type aliased in d.ts files? #1940

mpawelski opened this issue Feb 5, 2015 · 4 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@mpawelski
Copy link

I read that declare is required for all top level non-interface elements (i.e. module, class, var) in a declaration .d.ts file.

But do we need it for type aliases too?

Right now this code in tests.d.ts file gives error:

interface ITest {
    foo: string;
    bar: string;
}


type IMyAlias = ITest;

A 'declare' modifier is required for a top level declaration in a .d.ts file.

For me type aliases are similar to interfaces in this case and should not require declare keyword.

@danquirk danquirk added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 6, 2015
@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels May 4, 2015
@RyanCavanaugh
Copy link
Member

declare should be optional on type aliases and interfaces.

declare type and declare interface are identical to type and interface

@RyanCavanaugh RyanCavanaugh added this to the Community milestone May 4, 2015
@DanielRosenwasser
Copy link
Member

How does this affect #2994?

@yuit
Copy link
Contributor

yuit commented May 4, 2015

My understanding is that declare type is allowed as well as declare interface. So we need to stop giving an error for this case declare interface

@RyanCavanaugh
Copy link
Member

Yui's interpretation is correct.

Since we already shipped type aliases this way, people have had to write declare type a bunch of times. We could break them and say "Write type, not declare type", but that would be a massive break for no real reason.

Having made that decision, it's only logical to allow declare interface as a synonym for interface for consistency's sake. There are still some places where we're slightly inconsistent, but type and interface at least should be fully aligned.

@mhegazy mhegazy modified the milestones: TypeScript 1.6, Community May 5, 2015
@mhegazy mhegazy added the Bug A bug in TypeScript label May 5, 2015
@yuit yuit closed this as completed Jun 30, 2015
@yuit yuit added Fixed A PR has been merged for this issue and removed Help Wanted You can do this labels Jun 30, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants