microsoft / microsoft/TypeScript
Opaque types for WebGL
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
WebGL types are included in the default lib.d.ts. However, most types are defined as empty interfaces, which means that the compiler doesn't catch many WebGL errors.
Consider the following code:
function foo(gl: WebGLRenderingContext, fbo: WebGLFramebuffer) {
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); // Correct call
gl.bindFramebuffer(gl.FRAMEBUFFER, "abc"); // This should be a compile error!
fbo = gl.createFramebuffer(); // Correct call
fbo = new WebGLFramebuffer; // This should be a compile error!
}
- The second parameter of
gl.bindFramebuffershould be aWebGLFramebufferobject, but passing astringdoes not emit a compile error or warning. - The type
WebGLFramebuffercan only be constructed viaWebGLRenderingContext.createFramebuffer, calling new throws an error at runtime
Ideally, Typescript would know that WebGLFramebuffer, even though it has no public properties, cannot be constructed or converted to any other type.
I assume that this is not easy to specify with structural typing, but having such opaque types could be useful for other libraries as well (e.g., for returning handles).
If that is not possible, can we find a workaround that at least helps catching the above mentioned bugs?
For reference, here's how the above types are currently defined in lib.d.ts:
interface WebGLFramebuffer extends WebGLObject {
}
declare var WebGLFramebuffer: {
prototype: WebGLFramebuffer;
new(): WebGLFramebuffer;
}
interface WebGLRenderingContext {
bindFramebuffer(target: number, framebuffer: WebGLFramebuffer): void;
// + many other methods
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、lib.d.ts に示されている WebGLFramebuffer と WebGLRenderingContext の定義から始め、次にコンパイラーがそれらの構造型とコンストラクター宣言をどのように処理するかを追跡します。TypeScript が無効な bindFramebuffer 引数と直接構築を拒否する、合意されたメカニズムまたは回避策を持ち、その動作が適切なコンパイラーテストでカバーされて初めて、issue は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100