Skip to content

Commit 36892ae

Browse files
cieplypolariwoplaza
authored andcommitted
remove-index-signature (#2352)
1 parent 39f1c8e commit 36892ae

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

packages/typegpu/src/core/function/autoIO.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { BaseData, v4f } from '../../data/wgslTypes.ts';
77
import { getName, setName } from '../../shared/meta.ts';
88
import type { InferGPU, InferGPURecord, InferRecord } from '../../shared/repr.ts';
99
import { $internal, $resolve } from '../../shared/symbols.ts';
10-
import type { Assume } from '../../shared/utilityTypes.ts';
10+
import type { Assume, RemoveIndexSignature } from '../../shared/utilityTypes.ts';
1111
import type { TgpuVertexAttrib } from '../../shared/vertexFormat.ts';
1212
import type { ResolutionCtx, SelfResolvable } from '../../types.ts';
1313
import { shaderStageSlot } from '../slot/internalSlots.ts';
@@ -21,7 +21,8 @@ const builtinVertexIn = {
2121
$instanceIndex: builtin.instanceIndex,
2222
} as const;
2323

24-
export type AutoVertexIn<T extends AnyAutoCustoms> = T & InferRecord<typeof builtinVertexIn>;
24+
export type AutoVertexIn<T extends AnyAutoCustoms> = RemoveIndexSignature<T> &
25+
InferRecord<typeof builtinVertexIn>;
2526

2627
export type _AutoVertexIn<T> = AutoVertexIn<{
2728
[Key in keyof T]: T[Key] extends TgpuVertexAttrib
@@ -47,7 +48,8 @@ const builtinFragmentIn = {
4748
$subgroupSize: builtin.subgroupSize,
4849
} as const;
4950

50-
export type AutoFragmentIn<T extends AnyAutoCustoms> = T & InferRecord<typeof builtinFragmentIn>;
51+
export type AutoFragmentIn<T extends AnyAutoCustoms> = RemoveIndexSignature<T> &
52+
InferRecord<typeof builtinFragmentIn>;
5153

5254
const builtinFragmentOut = {
5355
$fragDepth: builtin.fragDepth,

packages/typegpu/src/core/function/tgpuFragmentFn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export declare namespace TgpuFragmentFn {
122122
type AutoIn<T extends AnyAutoCustoms> = AutoFragmentIn<T>;
123123
type AutoOut<T extends AnyAutoCustoms = AnyAutoCustoms> = AutoFragmentOut<T>;
124124

125-
type AutoInEmpty = AutoFragmentIn<{}>;
125+
type AutoInEmpty = AutoFragmentIn<Record<string, never>>;
126126
}
127127

128128
export function fragmentFn<FragmentOut extends FragmentOutConstrained>(options: {

packages/typegpu/src/core/function/tgpuVertexFn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export declare namespace TgpuVertexFn {
8787
type AutoIn<T> = _AutoVertexIn<T>;
8888
type AutoOut<T extends AnyAutoCustoms = AnyAutoCustoms> = AutoVertexOut<T>;
8989

90-
type AutoInEmpty = _AutoVertexIn<{}>;
90+
type AutoInEmpty = _AutoVertexIn<Record<string, never>>;
9191
}
9292

9393
export function vertexFn<VertexOut extends VertexOutConstrained>(options: {

packages/typegpu/src/shared/utilityTypes.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type Mutable<T> = {
5656
};
5757

5858
/**
59-
* Source: https://code.lol/post/programming/higher-kinded-types/
59+
* Source: https://code.lol/post/programming/higher-kinded-types
6060
*/
6161
export type Assume<T, U> = T extends U ? T : U;
6262

@@ -74,3 +74,16 @@ export type TypedArray =
7474
export function assertExhaustive(x: never, location: string): never {
7575
throw new Error(`Failed to handle ${x} at ${location}`);
7676
}
77+
78+
/**
79+
* Source: https://futurestud.io/tutorials/typescript-how-to-remove-index-signature-from-a-type
80+
*/
81+
export type RemoveIndexSignature<T> = {
82+
[K in keyof T as string extends K
83+
? never
84+
: number extends K
85+
? never
86+
: symbol extends K
87+
? never
88+
: K]: T[K];
89+
};

packages/typegpu/tests/renderPipeline.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ describe('root.createRenderPipeline', () => {
17951795

17961796
const fragment = ({ $position }: TgpuFragmentFn.AutoInEmpty) => {
17971797
'use gpu';
1798-
return d.vec4f($position);
1798+
return $position;
17991799
};
18001800

18011801
const pipeline = root.createRenderPipeline({

0 commit comments

Comments
 (0)