Strict types for WebGL and WebGL2

Open
#373 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reviewing the proposed types in TypeScript PR #21902 and its changed files, then inspect how auto-generated typings feed into dom.generated.d.ts. Determine whether WebGL/WebGL2 declarations should be additional inputs or a separate lib option, and assess the overload and shared-supertype concerns described in the issue. Done means an agreed integration approach and appropriate strict typings.

Written by the indexing model from the issue text.

Description

Opening a new issue, as requested. See also https://github.com/Microsoft/TypeScript/pull/21902.

I wrote some strict types for WebGL/WebGL2, which would fix https://github.com/Microsoft/TypeScript/issues/5855 among others. See https://github.com/Microsoft/TypeScript/pull/21902/files.

The auto-generated typings would need to be excluded. Maybe this should be added as a separate option for the lib compiler option as it's not exactly lightweight.

I might have made some of the types too strict, for example for texImage2D I added overloads which exactly match the internalFormat/format/type combinations allowed by the WebGL spec. When calling the function with immediate values, this is fine, but calling it with values in variables is going to require as any casts. (Which could be fine, as at that point you're responsible for the correct types anyway).

Also the following would fail, because TS doesn't currently generate a common supertype (?).

declare const randomParameter: GL['ACTIVE_TEXTURE'] | GL['ALIASED_LINE_WIDTH_RANGE']
const x = gl.getParameter(randomParameter)
// no matching overload, but a return type of GL.TextureUnits | Float32Array would make sense.

Is adding the .d.ts files as additional inputFiles which are concatenated to the dom.generated.d.ts (or a separate webgl lib file) an option? I added a number of subtypes which are only implicitly in the spec: all constants are typed as a generic GLenum in spec, although there are many different subgroups which I typed explicitly. It is highly unlikely that those will be added to the IDL.

Dominant language
TypeScript
Stars
740
Forks
474
Avg merge
2d 8h
Merged PRs (30d)
15

Contributor guide

No contributing guide indexed for this repository

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.

More from microsoft/TypeScript-DOM-lib-generator

All issues in microsoft/TypeScript-DOM-lib-generator

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.