diff --git a/.changeset/fresh-tigers-pull.md b/.changeset/fresh-tigers-pull.md new file mode 100644 index 0000000..9c0835c --- /dev/null +++ b/.changeset/fresh-tigers-pull.md @@ -0,0 +1,5 @@ +--- +"@crbroughton/ts-test-utils": minor +--- + +Add TupleElementAt diff --git a/index.ts b/index.ts index d856fcd..5da94d9 100644 --- a/index.ts +++ b/index.ts @@ -61,6 +61,8 @@ export type GetParameters = T extends (...args: infer P) => any ? P : never export type GetArrayUnion = T extends readonly (infer U)[] ? U : never +export type TupleElementAt = T[Index] + export type DeepReturnType = T extends (...args: unknown[]) => infer ReturnType ? ReturnType extends (...args: unknown[]) => unknown diff --git a/tests/TupleElementAt.test.ts b/tests/TupleElementAt.test.ts new file mode 100644 index 0000000..429f4d0 --- /dev/null +++ b/tests/TupleElementAt.test.ts @@ -0,0 +1,11 @@ +/* eslint-disable unused-imports/no-unused-vars */ +import type { Equals, Expect, TupleElementAt } from '..' + +// Passes the assignable test when the first type is assignable +type Result = Expect, 'b'>> +// ^? + +// Failed the TupleElementAt test - non-narrowed to the literal string +// @ts-expect-error - Fails the exclusion +type ResultFailure = Expect, string>> +// ^?