{"id":16931918,"url":"https://github.com/naridal/webgl-strict-types","last_synced_at":"2025-03-22T12:31:18.447Z","repository":{"id":29623588,"uuid":"121444286","full_name":"NaridaL/webgl-strict-types","owner":"NaridaL","description":"Strict TypeScript definitions for WebGL 1 \u0026 2.","archived":false,"fork":false,"pushed_at":"2022-12-12T10:29:22.000Z","size":232,"stargazers_count":16,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T11:04:32.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NaridaL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-13T22:29:30.000Z","updated_at":"2024-07-07T14:24:24.000Z","dependencies_parsed_at":"2023-01-14T15:20:02.558Z","dependency_job_id":null,"html_url":"https://github.com/NaridaL/webgl-strict-types","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaridaL%2Fwebgl-strict-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaridaL%2Fwebgl-strict-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaridaL%2Fwebgl-strict-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaridaL%2Fwebgl-strict-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NaridaL","download_url":"https://codeload.github.com/NaridaL/webgl-strict-types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244959409,"owners_count":20538625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T20:44:59.985Z","updated_at":"2025-03-22T12:31:16.718Z","avatar_url":"https://github.com/NaridaL.png","language":"TypeScript","readme":"# webgl-strict-types\nStrict types for WebGL and WebGL 2.0.\n\nThe included TypeScript typings for WebGL type all enum parameters as generic `GLenum = number`, as indeed does the specification.\nThis is too broad in basically all cases, for example, `bindRenderbuffer(target: GLenum, buffer: WebGLRenderbuffer | null)`\naccepts any number as target when in fact `gl.RENDERBUFFER` is the only valid value.\n\nA number of other cases can also\nbe modelled more accurately, such as literal number types for some parameters, as well as preventing `WebGLObject` types\n(such as `WebGLBuffer` and `WebGLRenderbuffer`) from being assignable to each other.\n\n\n## Installation\n```\nnpm install -D webgl-strict-types\n````\n## Usage\nYou need to explicitly include the types in your compilation. Use a triple slash statement:\n```ts\n/// \u003creference path=\"node_modules/webgl-strict-types/index.d.ts\" /\u003e\n```\nAlternatively, include them in your tsconfig:\n```json\n// tsconfig.json\n{\n    includes: [\n        'node_modules/webgl-strict-types/index.d.ts'\n    ]\n}\n```\n\n\nAs TypeScript already comes with (less strict) typings for WebGL/WebGL2, and this can't override\nthe existing typings, you need to cast the context explicitly:\n\n```ts\nconst gl = canvas.getContext('webgl') as any as WebGLRenderingContextStrict;\n\n// arrayBufferBinding is correctly inferred to be a WebGLBuffer\nconst arrayBufferBinding = gl.getParameter(gl.ARRAY_BUFFER_BINDING);\n\n// ERROR: Argument of type 'GLenum\u003c\"ARRAY_BUFFER\"\u003e' is not assignable to parameter of type 'GLenum\u003c\"FRAMEBUFFER\"\u003e'.\ngl.bindFramebuffer(gl.ARRAY_BUFFER, null)\n\n// You can use the defined types as follows:\nimport GL = WebGLRenderingContextStrict;\nconst WGL = WebGLRenderingContext as any as WebGLRenderingContextStrict.Constants;\nconst bufferTarget: GL.BufferTarget = gl.ARRAY_BUFFER;\nconst framebufferTarget: GL['FRAMEBUFFER'] = WGL.FRAMEBUFFER;\n\n// Without this lib, not an error:\nconst webGLBuffer: WebGLBuffer = gl.createRenderbuffer();\n```\n\nSee the definition files [webgl.d.ts](./webgl.d.ts) and [webgl2.d.ts](./webgl2.d.ts) for all available types.\n\n## License\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaridal%2Fwebgl-strict-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaridal%2Fwebgl-strict-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaridal%2Fwebgl-strict-types/lists"}