https://github.com/microsoft/TypeScript/issues/5453
[FixedTypes, OptionalTypes?, ...OneRestType[]]What if we loosened the restrictions?
[number, ...string[], boolean[number, ...[string, boolean], number]And of course, the magic question: what about generics? Does it work with generics?
Yes!
type T4<T extends any[]> = [number, ...T];
type T5 = T4<[string, string]>;
And if you feed in a union, it distributes
// [number] | [number, string] | [number, number, number]
type T6 = T4<[] | [string] | [number, number]>;
Okay, what about the more magical question: does inference "work" (i.e. does it work well) with this?
[...T, ...U]?Function.prototype.bind more simply.Also, could enable lots of super nice helper functions
type First<T> = T extends [infer U, ...any[]] ? U : never;
type DropFirst<T> = T extends [any, ...infer U] ? U : never;
type Last<T> = T extends [...any[], infer U] ? U : never;
curry - take a function of a parameter list of some length, return a function that takes the first and returns a function that takes the rest.Ideally, could write Zip
type Zip<T, U> = {
[K in (keyof T) & (keyof U)]: [T[K], U[K]]
};
// Doesn't work.
type Yadda = Zip<[1,2,3], [4,5,6]>;
@weswigham shows me it's possible
type Cast<T, U> = T extends U ? T : never;
type Zip<T, U, Hah = T | U> = { [K in keyof Hah]: [T [Cast<K, keyof T>], U[Cast<K, keyof U>]] };
type Yadda = Zip<[1, 2, 3], [4, 5, 6]>;
https://github.com/microsoft/TypeScript/pull/35282
https://github.com/microsoft/TypeScript/pull/38604
NodeFactorys between different versions?await can't be done with ambiguous parsing contexts (i.e. script .js vs module .mjs).https://gist.github.com/RyanCavanaugh/f80f9ddc50d45c4d76e7c4101efada28
undefined in indexed access types (currently too annoying)override keyword in classes (useless without noImplicitOverride or something)--pedantic?my-super-kewl-typscript-pedantic?pedanticYaddaYadda?strict and which is not.Especially looking forward to the pedantic mode.
BTW: We have a nickname for type-level operation: gymnastics of type.
As for pedantic mode, I like the idea! As already mentioned, some of this can be easily done with linter config. Some time ago I create TypeSTRICT which is ESlint/Tslint config focused on finding bugs code. so there might be some good candidates for pedantic rules.
I would love to see something like no-floating-promises as a built warning into tsc (as pedantic or strict flag).
Most helpful comment
Especially looking forward to the pedantic mode.
BTW: We have a nickname for type-level operation: gymnastics of type.