2

i'm learning ts, seriously, what's wrong with promises? :D

following function gives me this error

Type 'string | void' is not assignable to type 'string'. Type 'void' is not assignable to type 'string'.

export async function getType(serviceID: string, vendor: string, {inventory = defaultKeyinventory } = {}): Promise<string | null>{

    const item= inventory !.getItem(serviceID, vendor)
        .catch(() => console.log('error'));

    return item;
}

1 Answer 1

3

.catch returns a promise but you'll need to return something in your catch block. You'll need to return string or null.

export async function getType(
    serviceID: string, 
    vendor: string, 
    { inventory = defaultKeyinventory } = {}
): Promise<string | null>{

    const item= inventory !.getItem(serviceID, vendor)
        .catch(() => return null);

    return item;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.