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

Some generated guard fail to infer related types and default to checking instance of objects #188

Open
eko234 opened this issue Mar 30, 2022 · 3 comments
Labels
bug Something isn't working more information required

Comments

@eko234
Copy link

eko234 commented Mar 30, 2022

please include a warning or comment in the generated file...

@rhys-vdw
Copy link
Owner

Excuse me?

@eko234
Copy link
Author

eko234 commented Mar 30, 2022

Sorry I was in a hurry, let me explain what happens, maybe I'm doing something wrong...

I have these type definitions:

/** @see {isFilterValueKey} ts-auto-guard:type-guard */
export type FilterValueKey = "is" | "lt" | "gt" | "from" | "to" | "like"
/** @see {isFilterArrayKey} ts-auto-guard:type-guard */
export type FilterArrayKey = "in"
/** @see {isFilterValue} ts-auto-guard:type-guard */
export type FilterValue = { [key in FilterValueKey]?: RawValue } | { [key in FilterArrayKey]?: RawValue[] }
/** @see {isRawFilter} ts-auto-guard:type-guard */
export type RawFilter = { [key: string | symbol]: any } | { [key: string | symbol]: any }[]
/** @see {isFilterObject} ts-auto-guard:type-guard */
export type FilterObject = { [key: symbol | string]: FilterValue }
/** @see {isFilterObjectArray} ts-auto-guard:type-guard */
export type FilterObjectArray = FilterObject[]
/** @see {isFilter} ts-auto-guard:type-guard */
export type Filter = FilterObject | FilterObjectArray
/** @see {isFlag} ts-auto-guard:type-guard */
export type Flag = string
/** @see {isFlagArray} ts-auto-guard:type-guard */
export type FlagArray = Flag[]
/** @see {isRawValue} ts-auto-guard:type-guard */
export type RawValue = string | number | boolean | bigint | symbol | undefined | null
/** @see {isKeyToRawValue} ts-auto-guard:type-guard */
export type KeyToRawValue = { [key: string | symbol]: RawValue }
/** @see {isKeyToRawValueArray} ts-auto-guard:type-guard */
export type KeyToRawValueArray = KeyToRawValue[]

but the function isFilterObject that is emmited is like:

export function isFilterObject(obj: any, _argumentName?: string): obj is FilterObject {
    return (
        (obj !== null &&
            typeof obj === "object" ||
            typeof obj === "function")
    )
}

@rhys-vdw
Copy link
Owner

rhys-vdw commented Apr 4, 2022

@eko234 hm. Are other guards generated properly? were I to guess I'd say that it's not possible to check for symbol as a key, does it work properly if you drop symbol from the indexer?

@rhys-vdw rhys-vdw added more information required bug Something isn't working labels Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working more information required
Projects
None yet
Development

No branches or pull requests

2 participants