Microsoft/TypeScript

Conflict between imported namespace and global type in generated declaration file

Open

#48,121 建立於 2022年3月4日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: Declaration EmitHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

Bug Report

🔎 Search Terms

namespace import declaration conflict global types date-fns

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about declaration files

⏯ Playground Link

Playground link with relevant code

💻 Code

locale.ts:

export type T = {};

types.d.ts:

type Locale = {
  code?: string
}
declare module 'date-fns/locale' {
  const es: Locale
  namespace es {}
}

main.ts:

import { es } from "date-fns/locale";
import * as Locale from "./locale";

export const f = (locale: Locale.T) => es;

Run tsc with "declaration": true.

🙁 Actual behavior

tsc runs with no errors, but the following main.d.ts file is generated:

import * as Locale from "./locale";
export declare const f: (locale: Locale.T) => Locale;

When we try to use this .d.ts file in another TS project we get this error:

Cannot use namespace 'Locale' as a type

🙂 Expected behavior

No conflict. Perhaps the namespace import should be renamed in the .d.ts file.

貢獻者指南