microsoft / microsoft/TypeScript

Confusing/inconsistent error messages when erroring on disallowed merge

Offen
#59,808 9 Kommentare 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

@iisaduan arbeitet bereits daran.

Seit 26.9.2024.

Domain: Error Messages Possible Improvement
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔎 Search Terms

Duplicate identifier 'VueI18n'.
Subsequent property declarations must have the same type.

🕗 Version & Regression Information
  • This changed between versions 5.4.5 and 5.5.2

Behavior is the same with 5.7.0-dev.20240830

⏯ Playground Link

No response

💻 Code

shims-augment.d.ts:


/**
 * Overloads VueI18n interface to avoid needing to cast return value to string.
 * @see https://github.com/kazupon/vue-i18n/issues/410
 * It can be resolved with vue-i18n >= 9 (that only works with Vue 3 currently)
 */
import VueI18n from 'vue-i18n/types'
declare module 'vue-i18n/types' {
  export default class VueI18n {
    t (key: Path, locale: Locale, values?: Values): string
    t (key: Path, values?: Values): string
  }
}

declare module 'vue/types/vue' {
  interface Vue {
    $t: typeof VueI18n.prototype.t
  }
}

Excerpt of vue-i18n/types/index.d.ts:




declare namespace VueI18n {
  type Path = string;
  type Locale = string;
  type FallbackLocale = string | string[] | false | { [locale: string]: string[] }
  type Values = any[] | { [key: string]: any };
  type Choice = number;
  interface MessageContext {
    list(index: number): unknown
    named(key: string): unknown
    linked(key: string): VueI18n.TranslateResult
    values: any
    path: string
    formatter: Formatter
    messages: LocaleMessages
    locale: Locale
  }
  type MessageFunction = (ctx: MessageContext) => string;
  type LocaleMessage = string | MessageFunction | LocaleMessageObject | LocaleMessageArray;
  interface LocaleMessageObject { [key: string]: LocaleMessage; }
  interface LocaleMessageArray { [index: number]: LocaleMessage; }
  interface LocaleMessages { [key: string]: LocaleMessageObject; }
  type TranslateResult = string | LocaleMessages;
}

declare class VueI18n {
  constructor(options?: VueI18n.I18nOptions)

  readonly messages: VueI18n.LocaleMessages;
  readonly dateTimeFormats: VueI18n.DateTimeFormats;
  readonly numberFormats: VueI18n.NumberFormats;
  readonly availableLocales: VueI18n.Locale[];

  locale: VueI18n.Locale;
  fallbackLocale: VueI18n.FallbackLocale;
  missing: VueI18n.MissingHandler;
  formatter: VueI18n.Formatter;
  formatFallbackMessages: boolean;
  silentTranslationWarn: boolean | RegExp;
  silentFallbackWarn: boolean | RegExp;
  preserveDirectiveContent: boolean;
  pluralizationRules: VueI18n.PluralizationRulesMap;
  warnHtmlInMessage: VueI18n.WarnHtmlInMessageLevel;
  postTranslation: VueI18n.PostTranslationHandler;
  sync: boolean;

  t(key: VueI18n.Path, values?: VueI18n.Values): VueI18n.TranslateResult;
  t(key: VueI18n.Path, locale: VueI18n.Locale, values?: VueI18n.Values): VueI18n.TranslateResult;
}

declare module 'vue/types/vue' {
  interface Vue {
    readonly $i18n: VueI18n & IVueI18n;
    $t: typeof VueI18n.prototype.t;
  }
}

🙁 Actual behavior

Capture d’écran_2024-08-30_17-26-45

Capture d’écran_2024-08-30_17-28-08

On top of that, since $t is in error, my whole code base reports an error whenever it uses the returned value of $t as a string.

🙂 Expected behavior

No error were reported with 5.4.5

Additional information about the issue

I apologize if it's a feature, not a bug, but I wasn't able to find any info on this in the release notes.

I know that narrowing is not safe here, I'm wondering why it was allowed with old Typescript, and not anymore.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.