microsoft / microsoft/TypeScript

Object.getPrototypeOf returns `any` instead of `object | null`

Open
#22,875 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Breaking Change Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 2.7.2

Search Terms: Object.getPrototypeOf, ObjectConstructor.getPrototypeOf, wrong return type

Code

let prototype = Object.getPrototypeOf(foo);

Expected behavior:
The type of prototype should be object | null. According to the spec, getPrototypeOf returns the value of the internal property [[Prototype]] [1] whose values can only be of type object or null [2].

Actual behavior:
prototype has type any

Playground Link: here

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 at the ObjectConstructor.getPrototypeOf entry point and reproduce the example in the TypeScript playground. Check the declared return type against the ECMAScript behavior described in the issue; done means the inferred type is object | null rather than any.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.