lune-climate / ts-results-es

A TypeScript implementation of Rust's Result and Option.
MIT License
98 stars 8 forks source link

How to get typed result object after json deserialization #163

Closed EGSP closed 3 months ago

EGSP commented 3 months ago

I get function undefined

const response = await fetch('/api/users', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                nickname: $nickname,
                password: $password
            })
        });

        const result: Result<void, string[]> = await response.json() as Result<void, string[]>;

        console.log(result)
        if (result.isOk()) { // function undefined
            console.log('user created');
        } else {
            console.log(result.unwrapErr().join('\n'));
        }
    }