microsoft / microsoft/TypeScript

Module Namespace Exotic Objects are incorrectly typed as if they have an Object prototype

Open
#32,646 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.5.3

Search Terms:

  • import hasOwnProperty
  • import star hasOwnProperty
  • namespace exotic object
  • import prototype

Code

import * as Foo from "./Foo"
if (foo.hasOwnProperty("bar")) {
  console.log(foo.bar)
}

Expected behavior:

Type error due to hasOwnProperty not existing, as the "module namespace exotic object" should have a null prototype.

Actual behavior:

Code runs producing runtime error that hasOwnProperty is undefined.

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 example with TypeScript 3.5.3 and inspect how an import * as Foo namespace is typed. The issue is done when the compiler reports an error for hasOwnProperty, matching the specified null-prototype runtime behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.