Skip to content

Commit

Permalink
chore: TypeScript strict mode: noImplicitAny (#2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen authored Sep 22, 2024
1 parent 1a76402 commit 2182c5c
Show file tree
Hide file tree
Showing 30 changed files with 93 additions and 30 deletions.
28 changes: 27 additions & 1 deletion docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,33 @@ Target Date: Q4, 2024
Production quality WebGPU backend

**General**
- TypeScript v5.6, strictNullChecks enabled.
- TypeScript v5.6, all `"strict"` TypeScript options are now applied to all luma.gl modules.
- Website tooling upgrades
- All examples run on WebGPU
- Documentation improvements (TBD)
- Improved GitHub issue templates

**@luma.gl/core**

- Shader type APIs have been improved.
- `CommandEncoder`/`CommandBuffer` API improvements
- `Texture` class refactors complete.

**@luma.gl/engine**

- `AsyncTexture` now supports mipmap generation for WebGPU textures

**@luma.gl/effects**

- All postprocessing effects ported to WGSL (in progress)

**@luma.gl/shadertools**

- All shader modules ported to WGSL (in progress)

**@luma.gl/gltf**

- glTF and PRB now supported on WebGPU (in progress)


## Version 9.1 (In Beta)
Expand Down
1 change: 0 additions & 1 deletion modules/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"include": ["src/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"noImplicitAny": true,
"composite": true,
"rootDir": "src",
"outDir": "dist"
Expand Down
1 change: 0 additions & 1 deletion modules/effects/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"include": ["src/**/*"],
"exclude": ["node_modules", "test"],
"compilerOptions": {
"noImplicitAny": true,
"composite": true,
"rootDir": "src",
"outDir": "dist"
Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/src/gltf/create-gltf-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function createGLTFModel(device: Device, options: CreateGLTFModelOptions)
// Calculate managedResources
// TODO: Implement resource management logic that will
// not deallocate resources/textures/buffers that are shared
const managedResources = [];
const managedResources: any[] = [];
// managedResources.push(...parsedMaterial.generatedTextures);
// managedResources.push(...Object.values(attributes).map((attribute) => attribute.buffer));

Expand Down
2 changes: 2 additions & 0 deletions modules/gltf/src/gltf/gltf-animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

// @ts-nocheck TODO

import {log, TypedArray} from '@luma.gl/core';
import {Matrix4, Quaternion} from '@math.gl/core';

Expand Down
2 changes: 2 additions & 0 deletions modules/gltf/src/gltf/gltf-instantiator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

// @ts-nocheck TODO - fix types

import {Device, Buffer, PrimitiveTopology} from '@luma.gl/core';
import {Geometry, GeometryAttribute, GroupNode, ModelNode, ModelProps} from '@luma.gl/engine';
import {Matrix4} from '@math.gl/core';
Expand Down
8 changes: 7 additions & 1 deletion modules/gltf/src/pbr/parse-pbr-material.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// luma.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

// @ts-nocheck TODO

import type {Device, Texture, Parameters} from '@luma.gl/core';
import {log} from '@luma.gl/core';
import {PBREnvironment} from './pbr-environment';
Expand Down Expand Up @@ -46,7 +52,7 @@ enum GLEnum {
*/
export function parsePBRMaterial(
device: Device,
material,
material: any,
attributes: Record<string, any>,
options: ParsePBRMaterialOptions
): ParsedPBRMaterial {
Expand Down
5 changes: 4 additions & 1 deletion modules/gltf/src/pbr/pbr-environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// luma.gl, MIT license
// luma.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {Device, SamplerProps} from '@luma.gl/core';
import {AsyncTexture} from '@luma.gl/engine';
Expand Down Expand Up @@ -85,6 +87,7 @@ function makeCube(
): AsyncTexture {
const data = {};
FACES.forEach(face => {
// @ts-ignore TODO
data[String(face)] = getTextureForFace(face);
});
return new AsyncTexture(device, {
Expand Down
4 changes: 4 additions & 0 deletions modules/gltf/test/gltf/gltf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// luma.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import test from 'tape-promise/tape';
import {getWebGLTestDevice} from '@luma.gl/test-utils';

Expand Down
5 changes: 4 additions & 1 deletion modules/gltf/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// GLTF
// luma.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import './gltf/gltf.spec';
1 change: 0 additions & 1 deletion modules/gltf/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"include": ["src/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"noImplicitAny": false,
"composite": true,
"rootDir": "src",
"outDir": "dist"
Expand Down
1 change: 1 addition & 0 deletions modules/test-utils/src/create-test-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const withResolvers = <T>(): {
resolve = _resolve;
reject = _reject;
});
// @ts-ignore Assigned in callback.
return {promise, resolve, reject};
};

Expand Down
1 change: 1 addition & 0 deletions modules/test-utils/src/snapshot-test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class SnapshotTestRunner extends TestRunner {
};

// Take screenshot and compare
// @ts-ignore implicit any
const result = await globalThis.browserTestDriver_captureAndDiffScreen(diffOptions);

// invoke user callback
Expand Down
4 changes: 2 additions & 2 deletions modules/test-utils/src/utils/deep-copy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** Recursively copies objects */
export function deepCopy(object: Record<string, any>) {
export function deepCopy(object: any): any {
if (Array.isArray(object)) {
return object.map(element => deepCopy(element));
}

if (object !== null && typeof object === 'object') {
const newObject = {};
const newObject: Record<string, any> = {};
for (const key in object) {
newObject[key] = deepCopy(object[key]);
}
Expand Down
1 change: 0 additions & 1 deletion modules/test-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"include": ["src/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"noImplicitAny": false,
"composite": true,
"rootDir": "src",
"outDir": "dist"
Expand Down
2 changes: 2 additions & 0 deletions modules/webgl/src/adapter/converters/webgl-shadertypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function convertDataTypeToGLDataType(normalizedType: NormalizedDataType):
export function convertShaderVariableTypeToGLDataType(
normalizedType: VariableShaderType
): GLDataType {
// @ts-ignore TODO
return NORMALIZED_SHADER_TYPE_TO_WEBGL[normalizedType];
}

Expand All @@ -31,6 +32,7 @@ export function convertGLUniformTypeToShaderVariableType(

/** Check if a WebGL "uniform:" is a texture binding */
export function isGLSamplerType(type: GLUniformType | GLSamplerType): type is GLSamplerType {
// @ts-ignore TODO
return Boolean(WEBGL_SAMPLER_TO_TEXTURE_BINDINGS[type]);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/webgl/src/adapter/helpers/format-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {GL} from '@luma.gl/constants';

// Returns number of components in a specific readPixels WebGL format
export function glFormatToComponents(format) {
export function glFormatToComponents(format: GL): 0 | 1 | 2 | 3 | 4 {
switch (format) {
case GL.ALPHA:
case GL.R32F:
Expand Down Expand Up @@ -33,7 +33,7 @@ export function glFormatToComponents(format) {
}

// Return byte count for given readPixels WebGL type
export function glTypeToBytes(type) {
export function glTypeToBytes(type: GL): 0 | 1 | 2 | 4 {
switch (type) {
case GL.UNSIGNED_BYTE:
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function getFramebuffer(source: Texture | Framebuffer): {
* Returns number of components in a specific readPixels WebGL format
* @todo use shadertypes utils instead?
*/
export function glFormatToComponents(format): 1 | 2 | 3 | 4 {
export function glFormatToComponents(format: GL): 1 | 2 | 3 | 4 {
switch (format) {
case GL.ALPHA:
case GL.R32F:
Expand Down
4 changes: 2 additions & 2 deletions modules/webgl/src/adapter/resources/webgl-render-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class WEBGLRenderPass extends RenderPass {
this.device = device;

// If no viewport is provided, apply reasonably defaults
let viewport;
let viewport: NumberArray4 | undefined;
if (!props?.parameters?.viewport) {
if (props?.framebuffer) {
// Set the viewport to the size of the framebuffer
Expand Down Expand Up @@ -114,7 +114,7 @@ export class WEBGLRenderPass extends RenderPass {
console.warn('RenderPassParameters.stencilReference not yet implemented in WebGL');
// parameters.stencilFunc = [func, ref, mask];
// Does this work?
parameters[GL.STENCIL_REF] = parameters.stencilReference;
glParameters[GL.STENCIL_REF] = parameters.stencilReference;
}

if ('colorMask' in parameters) {
Expand Down
2 changes: 2 additions & 0 deletions modules/webgl/src/context/debug/spector-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Forked from https://github.com/BabylonJS/Spector.js/blob/master/dist/spector.d.ts
/* eslint-disable camelcase, no-shadow */

// @ts-nocheck

interface IEvent<T> {
add(callback: (element: T) => void, context?: any): number;
remove(id: number): void;
Expand Down
11 changes: 8 additions & 3 deletions modules/webgl/src/context/debug/webgl-developer-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,20 @@ function getDebugContext(

// DEBUG TRACING

function getFunctionString(functionName: string, functionArgs): string {
function getFunctionString(functionName: string, functionArgs: unknown[]): string {
// Cover bug in webgl-debug-tools
functionArgs = Array.from(functionArgs).map(arg => (arg === undefined ? 'undefined' : arg));
let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);
args = `${args.slice(0, 100)}${args.length > 100 ? '...' : ''}`;
return `gl.${functionName}(${args})`;
}

function onGLError(props: DebugContextProps, err, functionName: string, args: any[]): void {
function onGLError(
props: DebugContextProps,
err: number,
functionName: string,
args: unknown[]
): void {
// Cover bug in webgl-debug-tools
args = Array.from(args).map(arg => (arg === undefined ? 'undefined' : arg));
const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
Expand All @@ -135,7 +140,7 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an
function onValidateGLFunc(
props: DebugContextProps,
functionName: string,
functionArgs: any[]
functionArgs: unknown[]
): void {
let functionString: string = '';
if (log.level >= 1) {
Expand Down
3 changes: 3 additions & 0 deletions modules/webgl/src/context/helpers/webgl-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ export function getWebGLExtension(
name: string,
extensions: GLExtensions
): unknown {
// @ts-ignore TODO
if (extensions[name] === undefined) {
// @ts-ignore TODO
extensions[name] = gl.getExtension(name) || null;
}
// @ts-ignore TODO
return extensions[name];
}
11 changes: 9 additions & 2 deletions modules/webgl/src/context/parameters/unified-parameter-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ export function setGLParameters(gl: WebGL2RenderingContext, parameters: GLParame

for (const key in parameters) {
const glConstant = Number(key);
// @ts-ignore TODO
const setter = GL_PARAMETER_SETTERS[key];
if (setter) {
// Composite setters should only be called once, so save them
if (typeof setter === 'string') {
// @ts-ignore TODO
compositeSetters[setter] = true;
} else {
// if (gl[glConstant] !== undefined) {
// TODO - added above check since this is being called on WebGL2 parameters in WebGL1...
// TODO - deep equal on values? only call setter if value has changed?
// NOTE - the setter will automatically update this.state
// @ts-ignore TODO
setter(gl, parameters[key], glConstant);
}
}
Expand All @@ -59,6 +62,7 @@ export function setGLParameters(gl: WebGL2RenderingContext, parameters: GLParame
if (cache) {
for (const key in compositeSetters) {
// TODO - avoid calling composite setters if values have not changed.
// @ts-ignore TODO
const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];
// Note - if `trackContextState` has been called,
// the setter will automatically update this.state.cache
Expand Down Expand Up @@ -92,15 +96,18 @@ export function getGLParameters(
if (typeof parameters === 'number') {
// single GL enum
const key = parameters;
// @ts-ignore TODO
const getter = GL_PARAMETER_GETTERS[key];
return getter ? getter(gl, key) : gl.getParameter(key);
}

const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);

const state = {};
const state: GLParameters = {};
for (const key of parameterKeys) {
// @ts-ignore TODO
const getter = GL_PARAMETER_GETTERS[key];
// @ts-ignore TODO
state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));
}
return state;
Expand All @@ -119,7 +126,7 @@ export function resetGLParameters(gl: WebGL2RenderingContext): void {
// Helpers

// Returns true if given object is empty, false otherwise.
function isObjectEmpty(object) {
function isObjectEmpty(object: Record<string, unknown>): boolean {
// @ts-ignore dummy key variable
for (const key in object) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

// @ts-nocheck TODO fix

// Tables describing WebGL parameters
import {GL, GLParameters} from '@luma.gl/constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export function polyfillWebGL1Extensions(gl: WebGL2RenderingContext): void {

// Injected extensions
if (extensionName in boundExtensions) {
// @ts-ignore TODO string index
return boundExtensions[extensionName];
}

Expand Down
10 changes: 5 additions & 5 deletions modules/webgl/src/context/state-tracker/deep-array-equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ export function deepArrayEqual(
if (x === y) {
return true;
}
const isArrayX = Array.isArray(x) || ArrayBuffer.isView(x);
const isArrayY = Array.isArray(y) || ArrayBuffer.isView(y);
// @ts-expect-error TODO fix
if (isArrayX && isArrayY && x.length === y.length) {
// @ts-expect-error TODO fix
if (isArray(x) && isArray(y) && x.length === y.length) {
for (let i = 0; i < x.length; ++i) {
if (x[i] !== y[i]) {
return false;
Expand All @@ -26,3 +22,7 @@ export function deepArrayEqual(
}
return false;
}

function isArray(x: unknown): x is unknown[] {
return Array.isArray(x) || ArrayBuffer.isView(x);
}
2 changes: 1 addition & 1 deletion modules/webgl/src/context/state-tracker/with-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function withGLParameters(
// Helpers

// Returns true if given object is empty, false otherwise.
function isObjectEmpty(object) {
function isObjectEmpty(object: unknown): boolean {
// @ts-ignore - dummy key variable
for (const key in object) {
return false;
Expand Down
1 change: 0 additions & 1 deletion modules/webgl/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"include": ["src/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
"noImplicitAny": false,
"composite": true,
"rootDir": "src",
"outDir": "dist"
Expand Down
Loading

0 comments on commit 2182c5c

Please sign in to comment.