Microsoft/TypeScript

[isolatedDeclarations] Type of const variable declared with template literal expression containing only literals still requires explicit annotation

オープン

#59,157 opened on 2024/07/06

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)TypeScript (13,395 件のフォーク)batch import
Domain: flag: isolatedDeclarationsHelp WantedPossible Improvement

Repository metrics

Stars
 (108,860 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 9 merged PRs)

説明

🔎 Search Terms

isolated declarations template literal expression

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?isolatedDeclarations=true&ts=5.6.0-dev.20240705#code/KYDwDg9gTgLgBAG2PAZhCcC8cAGASAbwHIiBfHAbgCgrRJY4BjCAOwGd4AjAQyi10Ily1WuGioAri0YwAlqzg8AXgAoAlHAJU4OuFGQSoLAcTKUqpIA

💻 Code

export let foo = `${''}`;

export const bar = `${''}`;

export function baz() {
    return `${''}`;
}

🙁 Actual behavior

bar has a type error:

Variable must have an explicit type annotation with --isolatedDeclarations.(9010)
input.tsx(3, 14): Add a type annotation to the variable bar.

foo would also have a type error if as const was added to the expression.

🙂 Expected behavior

No type error

Additional information about the issue

fun fact: I accidentally discovered this behavior when I found that oxc-transform has type errors for both const, let, and return types.

コントリビューターガイド