Skip to content
New issue

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

Rest elements in Tuple Types to support NonEmptyArray #228

Open
jmatsushita opened this issue Apr 13, 2023 · 1 comment
Open

Rest elements in Tuple Types to support NonEmptyArray #228

jmatsushita opened this issue Apr 13, 2023 · 1 comment
Labels
enhancement New feature or request pr requested

Comments

@jmatsushita
Copy link

Hi there,

Thanks for the great library. I just ran into an issue with a trick I use to specify a non empty list in typescript:

export type Item = string;
export type NonEmptyArray = [Item, ...Item[]];

ts-auto-guard generates:

/*
 * Generated type guards for "nonempty.ts".
 * WARNING: Do not manually change this file.
 */
import { NonEmptyArray } from "./nonempty";

export function isNonEmptyArray(obj: unknown): obj is NonEmptyArray {
    const typedObj = obj as NonEmptyArray
    return (
        Array.isArray(typedObj) &&
        typeof typedObj[0] === "string" &&
        typeof typedObj[1] === "string"
    )
}

Which means it's expecting an Array of 2 elements. I suppose that the rest elements in tuple types is not implemented ?

@rhys-vdw rhys-vdw added enhancement New feature or request pr requested labels Apr 14, 2023
@rhys-vdw
Copy link
Owner

@jmatsushita not that I'm aware of. You're welcome to have a go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pr requested
Projects
None yet
Development

No branches or pull requests

2 participants