Skip to content

Any file name with .d. in it ending with .ts is a declaration file in 5.0.2 even without --allowArbitraryExtensions #53319

Closed
@dsherret

Description

@dsherret

Bug Report

See the last "or" condition:

TypeScript/src/compiler/parser.ts

Lines 10178 to 10180 in a70c409

export function isDeclarationFileName(fileName: string): boolean {
return fileExtensionIsOneOf(fileName, supportedDeclarationExtensions) || (fileExtensionIs(fileName, Extension.Ts) && stringContains(getBaseFileName(fileName), ".d."));
}

Added as part of #51435 -- I think this was meant to be behind the --allowArbitraryExtensions flag?

> function checkAmbient(fileUrl) {
    const s = ts.createSourceFile(fileUrl, "");
    console.log((s.flags & ts.NodeFlags.Ambient) === ts.NodeFlags.Ambient)
}
undefined
> ts.version
'5.0.2'
> checkAmbient("file:///V:/test.d.ts$22-28.ts")
true
> checkAmbient("file:///V:/test.d.tsblah.ts")
true
> ts.version
'4.9.5'
> checkAmbient("file:///V:/test.d.ts$22-28.ts")
false
> checkAmbient("file:///V:/test.d.ts22-28.ts")
false

Right now the only way I see to set if a file type is ambient is through the extension. Maybe the API needs a better way for consumers to tell it "this is a declaration file"? Maybe on CreateSourceFileOptions? Then perhaps the code that does the arbitrary extension resolution could mark the declaration file that matches the arbitrary extension as ambient and the code here could be reverted.

🔎 Search Terms

extension declaration

🕗 Version & Regression Information

  • 5.0.2
  • I see this in main

🙁 Actual behavior

Declaration file specific errors

🙂 Expected behavior

No declaration file errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions