Typescript: WebGLShader has no properties

Created on 16 Dec 2019  路  3Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.7.3


Search Terms: array element type checking, error type checking, stops checking function argument types

Code
https://github.com/vjancik/dont-find-me-yet/blob/tsc-issue/src/index.ts#L63-L64

  • fails to infer a possible Error type
  • and if I set it explicitly (see Playground), fails to enforce it in

https://github.com/vjancik/dont-find-me-yet/blob/tsc-issue/src/index.ts#L146

  • createProgram doesn't enforce WebGLShader[] at all on the first argument, or seemingly any of the other arguments as well. I can add any variable in there and the array accepts it (also Playground)

Expected behavior:
Types of fn. arguments on createProgram get enforced correctly.
Optional: Return type on loadShader & createProgram gets inferred correctly as ... | Error

Actual behavior:
The issue doesn't resolve even if I specify all return types on all functions manually.

Playground Link:
Playground link

Related Issues:
No, there are multiple problems and I can't pinpoint the cause in a very specific setup.

Bug lib.d.ts

Most helpful comment

No

All 3 comments

The root cause here is that WebGLShader is an empty type, which causes all sorts of downstream problems. We should do something with it so this doesn't happen.

Just a thought, but isn't it possible to have a "strict / strong" typing flag that enforces a prototype instead of just the properties (duck typing)?
I suspect there will be more and more opaque types in the future as the Web standard becomes more and more integrated with the OS.

No

Was this page helpful?
0 / 5 - 0 ratings