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

Asserts on functions defined using function statements do not work #50373

Closed
pawbor opened this issue Aug 19, 2022 · 2 comments
Closed

Asserts on functions defined using function statements do not work #50373

pawbor opened this issue Aug 19, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@pawbor
Copy link

pawbor commented Aug 19, 2022

Bug Report

πŸ”Ž Search Terms

asserts function declaration

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function fn<T>(val: T) {
    return { val }
}

const fnLambda = function <T>(val: T) { return { val } };

const arrow = <T,>(val: T) => ({ val });

type AnyFunction = (...args: never[]) => unknown;

function enhance<Fn extends AnyFunction>(fn: Fn): asserts fn is Fn & { enhanced: true } {
    Object.assign(fn, { enhanced: true } as const);
}

(function runner1() {
    enhance(fn);
    enhance(fnLambda);
    enhance(arrow);

    console.log(fn.enhanced)
    console.log(fnLambda.enhanced)
    console.log(arrow.enhanced)
}())

πŸ™ Actual behavior

Assertion does not work for function declaration but it works for function expressions / arrow functions.

πŸ™‚ Expected behavior

I expect same behavior in all 3 cases.

@MartinJohns
Copy link
Contributor

Duplicate of #41232. Used search terms: asserts function in:title

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 19, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants