microsoft / microsoft/TypeScript
No way to type an object with null prototype
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Currently the base type of all objects in TS seems to be `{}`, which looks like an empty type but actually has members inherited from the Object object. This leaves no way to express a type with null prototype.
``` javascript
var foo: ??? = Object.create(null);
foo.toString(); // Want a compile error here
```
I did accidentally discover that it's possible to type a variable as void:
``` javascript
var foo: void = Object.create(null);
```
This appears to suppress intellisense for members in VS and the playground, and it is assignable to `any` (`Object.keys(foo)` compiles), so it would seem to be what I'm looking for. However this still lets `foo.toString()` compile somehow - I imagine the void type is getting elevated to Object automatically.
Edit: [Ryan's workaround](https://github.com/Microsoft/TypeScript/issues/1108#issuecomment-62406685) to subtype Object and override all its members to void prevents those properties from being called as functions, but as he points out, that doesn't prevent them from being accessed.
``` javascript
var bar = foo.toString; // Want a compiler error here too. Won't get one with Ryan's workaround.
```
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
TypeScript playground で Object.create(null) の例を再現し、その後、{}, void、Object のメンバーがどのようにモデル化されているかを追跡します。対応する型が null プロトタイプのオブジェクトを表現でき、メンバーアクセスの両方の例を拒否できれば完了です。この issue では対象とするファイルやテストは指定されていません。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100