microsoft / microsoft/TypeScript

`symbol` does not match interface

Open
#29,713 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: lib.d.ts
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: playground and 3.3

Search Terms: symbol interface

Code

const sym: symbol = Symbol();

function f(arg: { constructor?: unknown }): void {
}

f(sym);

Expected behavior:
symbol is a non-nullish primitive, as such, it should be able to potentially match any interface.

Actual behavior:
Type error.

Playground Link: https://www.typescriptlang.org/play/#src=const%20sym%3A%20symbol%20%3D%20Symbol()%3B%0D%0A%0D%0Afunction%20f(arg%3A%20%7B%20constructor%3F%3A%20unknown%20%7D)%3A%20void%20%7B%0D%0A%7D%0D%0A%0D%0Af(sym)%3B

Related Issues: #29536 (discovered in relation to #28900), #1863, #24587

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided example in the linked TypeScript Playground and review the related issues for the intended assignability behavior. Trace the compiler's handling of symbol values against the { constructor?: unknown } interface, then add a regression test and verify that the example type-checks without weakening unrelated type rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.