Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Fix typings #2242

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions modules/engine/src/shader-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export class ShaderInputs<
* The map of modules
* @todo should should this include the resolved dependencies?
*/
// @ts-expect-error Fix typings
modules: Readonly<{[P in keyof ShaderPropsT]: ShaderModule<ShaderPropsT[P]>}>;
modules: Readonly<{[P in keyof ShaderPropsT]: ShaderModule<Record<string, any>>}>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this change throws away the knowledge of the type the props of a ShaderModule has, which seems like a shame.

Perhaps we are trying to be too clever with the types here though and for now we can go with ShaderModule<Record<string, unknown>>, what do you think @ibgreen? Realistically, I'm not going to have the bandwidth to look at this for a few weeks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that having types for the shader module props is a major improvement in v9 that we don't want to give up without a deep understanding of what is going wrong.

What we could perhaps consider is landing this on the 9.0-release branch instead of master. But still I would much rather we root cause and fix the issue rather than just remove typing.


/** Stores the uniform values for each module */
moduleUniforms: Record<keyof ShaderPropsT, Record<string, UniformValue>>;
Expand All @@ -38,8 +37,7 @@ export class ShaderInputs<
* Create a new UniformStore instance
* @param modules
*/
// @ts-expect-error Fix typings
constructor(modules: {[P in keyof ShaderPropsT]?: ShaderModule<ShaderPropsT[P], any>}) {
constructor(modules: {[P in keyof ShaderPropsT]?: ShaderModule<Record<string, any>, any>}) {
// Extract modules with dependencies
const resolvedModules = getShaderModuleDependencies(
Object.values(modules).filter(module => module.dependencies)
Expand All @@ -52,8 +50,7 @@ export class ShaderInputs<
log.log(1, 'Creating ShaderInputs with modules', Object.keys(modules))();

// Store the module definitions and create storage for uniform values and binding values, per module
// @ts-expect-error Fix typings
this.modules = modules as {[P in keyof ShaderPropsT]: ShaderModule<ShaderPropsT[P]>};
this.modules = modules as {[P in keyof ShaderPropsT]: ShaderModule<Record<string, any>>};
this.moduleUniforms = {} as Record<keyof ShaderPropsT, Record<string, UniformValue>>;
this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, Binding>>;

Expand All @@ -72,7 +69,7 @@ export class ShaderInputs<
/**
* Set module props
*/
setProps(props: Partial<{[P in keyof ShaderPropsT]?: Partial<ShaderPropsT[P]>}>): void {
setProps(props: Partial<{[P in keyof ShaderPropsT]?: Partial<Record<string, any>>}>): void {
for (const name of Object.keys(props)) {
const moduleName = name as keyof ShaderPropsT;
const moduleProps = props[moduleName] || {};
Expand Down
Loading