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

this seems wrong #242

Closed
github-actions bot opened this issue Apr 14, 2023 · 1 comment
Closed

this seems wrong #242

github-actions bot opened this issue Apr 14, 2023 · 1 comment
Labels

Comments

@github-actions
Copy link

https://api.github.com/DetachHead/ts-helpers/blob/6c4b860f5fda1f2e96a416e677cd60af2e216b97/test/functions/misc.spec.ts#L612

        )
    })
})

describe('optionalProperties', () => {
    describe('object', () => {
        test('top level', () => {
            exactly(
                // TODO: this seems wrong
                { a: 1 } as { a: number; b: never },
                optionalProperties({ a: 1, b: undefined }),
            )
        })
        test('nested', () => {
            exactly(
                // @ts-expect-error xfail TODO: figure out why exactly doesn't work on nested ToExactOptionalProperties types
                { a: { a: 1 } } as { a: { a: number; b?: string } },
                optionalProperties({
                    a: { a: 1, b: undefined },
                }),
            )
        })
    })
    test('array', () => {
        exactly(
            { a: [{ a: 1 }] } as { a: [{ a: number; b?: string }] },
            // @ts-expect-error xfail TODO: figure out why exactly doesn't work on arrays in ToExactOptionalProperties
            optionalProperties({
                a: [{ a: 1, b: undefined }],
            }),
        )
    })
    describe('real world examples', () => {
        interface Expected {
            a: number
            b?: string
        }
        test('sanity check', () => {
            optionalProperties({ a: 1, b: '' }) satisfies Expected
        })
        test('positive', () => {
            const actual = { a: 1, b: Math.random() === 1 ? '' : undefined }
            // @ts-expect-error sanity check. if this is no longer an error then exactOptionalPropertyTypes was probably turned off
            actual satisfies Expected
            optionalProperties(actual) satisfies Expected
        })
        describe('negative', () => {
            test('optional type is wrong', () => {
                // @ts-expect-error type is wrong
                optionalProperties({ a: 1, b: true }) satisfies Expected
            })
            test('mandatory type is wrong', () => {
                // @ts-expect-error type is wrong
                optionalProperties({ a: '', b: '' }) satisfies Expected
            })
        })
    })
})
@github-actions github-actions bot added the todo label Apr 14, 2023
@DetachHead
Copy link
Owner

#241

@DetachHead DetachHead closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant