File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,7 +38,9 @@ export type Infer<T> = T extends { readonly [$repr]: infer TRepr } ? TRepr : T;
3838 * const arrayOfStructs = d.arrayOf(d.struct({ pos: d.vec3f, id: d.f32 }), 4);
3939 * type D = d.InferInput<typeof arrayOfStructs>; // { pos: d.v3f | Float32Array<ArrayBufferLike> | [number, number, number]; id: number; }[]
4040 */
41- export type InferInput < T > = T extends { readonly [ $inRepr ] : infer TRepr } ? TRepr : Infer < T > ;
41+ export type InferInput < T > =
42+ | Infer < T >
43+ | ( T extends { readonly [ $inRepr ] : infer TRepr } ? TRepr : never ) ;
4244
4345/**
4446 * Extracts a sparse/partial inferred representation of a resource.
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import { getName } from '../src/shared/meta.ts';
88import type { IsValidBufferSchema , IsValidUniformSchema } from '../src/shared/repr.ts' ;
99import type { TypedArray } from '../src/shared/utilityTypes.ts' ;
1010import { it } from 'typegpu-testing-utility' ;
11- import { buildWriter } from '../src/data/compiledIO.ts' ;
1211
1312function toUint8Array ( ...arrays : Array < TypedArray > ) : Uint8Array {
1413 let totalByteLength = 0 ;
@@ -846,7 +845,7 @@ describe('TgpuBuffer (InferInput)', () => {
846845 expectTypeOf ( arrBuf . write )
847846 . parameter ( 0 )
848847 . toEqualTypeOf <
849- ( d . v3f | [ number , number , number ] | Float32Array ) [ ] | Float32Array | ArrayBuffer
848+ ( d . v3f | [ number , number , number ] | Float32Array ) [ ] | Float32Array | ArrayBuffer | d . v3f [ ]
850849 > ( ) ;
851850
852851 expectTypeOf ( scalarArrBuf . write )
Original file line number Diff line number Diff line change 1+ import { test } from 'typegpu-testing-utility' ;
2+ import { describe , expect } from 'vitest' ;
3+ import { d , ValidateBufferSchema } from 'typegpu' ;
4+
5+ describe ( 'd.InferInput' , ( ) => {
6+ test ( 'd.Infer<T> should be assignable to d.InferInput<T>' , ( { root } ) => {
7+ function foo < T extends d . AnyWgslData > ( schema : ValidateBufferSchema < T > , input : d . Infer < T > ) {
8+ return root . createBuffer ( schema , input ) ;
9+ }
10+
11+ expect ( ( ) => foo ( d . f32 , 1 ) ) . not . toThrow ( ) ;
12+ } ) ;
13+ } ) ;
You can’t perform that action at this time.
0 commit comments