Microsoft/TypeScript

`satisfies` does not work on a variable called `type`

Open

#58,248 建立於 2024年4月19日

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

倉庫指標

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

描述

🔎 Search Terms

satisfies, type, ts1005

🕗 Version & Regression Information

This happens from 3.3.3333 to nightly.

satisfies was introduced in 4.9.

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYewdgzgLgBFCeAHApjAvDA5AD0wKDwRRggEMoBLCAMwuQhKgCcKwBzPIA

💻 Code

const type = 'x'

type satisfies string // '=' expected.(1005)

🙁 Actual behavior

Gives an '=' expected.(1005) error.

🙂 Expected behavior

For it to work like with any other variable of any other name, specially since it's a common variable name.

Additional information about the issue

This also happens with other TypeScript keywords like interface.

If I wrap type in parenthesis it works, is this expected behaviour? The Deno formatter removes it (prettier handles it correctly), should I report this to them.

貢獻者指南