We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Repeat , Array , Repeat Type
Repeat
Array
Repeat Type
My suggestion meets these guidelines:
I'd like to shortnize repeated array types like this:
type Number32 = Repeat<number, 32>;
When i made my own Matrix class, there's some pretty uncomfortable code for matrix value type.
Code like this:
type Matrix4x4Value = [number, number, number, /* ... */ , number]; // 16 numbers! type Matrix4x5Value = [number, number, number, /* ... */ , number]; // 20 numbers!!
Very tired and difficult to check about what times i wrote...
So i tried to use Repeat type for those, like this (with generated programatically code):
type Repeat1<T> = [T]; type Repeat2<T> = [T, T]; /* ... */ type Repeat16<T> = [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T]; type Repeat17<T> = [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T]; type Repeat18<T> = [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T]; type Repeat19<T> = [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T]; type Repeat20<T> = [T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T]; /* ... */ type Repeat100<T> = [T, T, T, T, T, T, T, T, /* ... */ , T, T, T, T]; // 100 T export type Repeat<T, R extends Number> = R extends 1 ? Repeat1<T> : R extends 2 ? Repeat2<T> : R extends 3 ? Repeat3<T> : R extends 4 ? Repeat4<T> : R extends 5 ? Repeat5<T> ... : R extends 15 ? Repeat15<T> : R extends 16 ? Repeat16<T> : R extends 17 ? Repeat17<T> : R extends 18 ? Repeat18<T> : R extends 19 ? Repeat19<T> : R extends 20 ? Repeat20<T> ... : R extends 100 ? Repeat100<T> : T[]; // not defined, just use plain array
Looks very dirty code but works well.
And my Matrix code has changed to:
type Matrix4x4Value = Repeat<number, 16>; // Easy to use type Matrix4x5Value = Repeat<number, 20>; // and Easy to know
Just for type-checking feature, as i think.
Fixed-length single type array like Matrix value type as in Example section, to use in WebGL or something.
The text was updated successfully, but these errors were encountered:
Duplicate of #50838.
Sorry, something went wrong.
Ah i missed it. Thanks!
No branches or pull requests
Suggestion
π Search Terms
Repeat
,Array
,Repeat Type
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
I'd like to shortnize repeated array types like this:
π Motivating Example
When i made my own Matrix class, there's some pretty uncomfortable code for matrix value type.
Code like this:
Very tired and difficult to check about what times i wrote...
So i tried to use Repeat type for those, like this (with generated programatically code):
Looks very dirty code but works well.
And my Matrix code has changed to:
Just for type-checking feature, as i think.
π» Use Cases
Fixed-length single type array like Matrix value type as in Example section, to use in WebGL or something.
The text was updated successfully, but these errors were encountered: