Skip to content

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

Closed

Description

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.

Activity

  1. RyanCavanaugh commented on May 4, 2015

    @RyanCavanaugh
    Member

    declare should be optional on type aliases and interfaces.

    declare type and declare interface are identical to type and interface

  2. added this to the milestone on May 4, 2015
  3. DanielRosenwasser commented on May 4, 2015

    @DanielRosenwasser
    Member

    How does this affect #2994?

  4. yuit commented on May 4, 2015

    @yuit
    Contributor

    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

  5. RyanCavanaugh commented on May 5, 2015

    @RyanCavanaugh
    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.

  6. modified the milestones: TypeScript 1.6, on May 5, 2015
  7. added
    FixedA PR has been merged for this issue
    and removed on Jun 30, 2015
  8. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions