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

Странно работают типы при наследовании de-блока #16

Open
doochik opened this issue Apr 20, 2021 · 0 comments

Comments

@doochik
Copy link
Contributor

doochik commented Apr 20, 2021

Если сделать вот так, то method выводится как
const method: de.DescriptHttpBlock<Context, any, any>

Если убрать дженерик из de.http, то все ломается, потому что method превращается в
const method: de.DescriptHttpBlock<unknown, unknown, unknown>.

Идеальный для меня вариантом было бы писать вот так:

import de from 'descript';

interface Context {
    foo: string;
}

// определяем базовый http-блок с общим для всех Context
// params и result будут определены в конкретных блоках
const baseHttpBlock = de.http<Context, unknown, unknown>({
    block: {
        family: 6,
        timeout: 1000,
    },
});

interface Params {
    param1: string;
}

interface ResultIn {
    status_code: number;
    result: {
        bar: string;
        foo: string;
    }
}

interface ResultOut {
    bar: string;
}

const method = baseHttpBlock<Params, ResultIn, ResultOut>({
    block: {
        method: 'GET',
        pathname: '/pathname',
        // автовывод Params
        query: ({ params }) => {
            return {
                param1: params.param1,
            };
        },
    },
    options: {
        // автовывод ResultIn и ResultOut
        after: ({ result }) => result.bar,
    },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant