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

Assignability to asserts type predicate is not checked #58219

Closed
gabritto opened this issue Apr 16, 2024 · 2 comments
Closed

Assignability to asserts type predicate is not checked #58219

gabritto opened this issue Apr 16, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@gabritto
Copy link
Member

πŸ”Ž Search Terms

asserts assignability

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240416&ssl=9&ssc=2&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChkHJwDOx0YAFAB4BcyAriANYjoDuIAlHSWVGMWRVkwQQCI4YgNz5CvcgCE4UanUYt2XHqXKCwAC1EjBSqDIC+uXKEixEKU8ghVIIACaCMWPISI7+qgzMrBzcyCD0ALYARtAyvvL8poHqIVrIxGBQoADmFkA

πŸ’» Code

interface Foo {
    assert(x: unknown): asserts x is "a";
    assertBar(x: unknown): asserts this is Bar;
}

interface Bar extends Foo {
    assert(x: unknown): number;
    assertBar(x: unknown): string;
}

πŸ™ Actual behavior

No errors on Bar.

πŸ™‚ Expected behavior

Errors on Bar about assert and assertBar's signatures not being assignable to their counterparts in Foo.

Additional information about the issue

Follow up of #57103.

@fatcerberus
Copy link

fatcerberus commented Apr 17, 2024

Simplified repro:

declare type Asserter = (x: unknown) => asserts x is "a";
declare const fun: (x: unknown) => number;
const assert: Asserter = fun;  // no error

It has nothing to do with assignability checking during inheritance - it's that non-assertion functions are, in fact, (unsoundly) assignable to assertion function types. This is probably a side effect of (x: unknown) => number being assignable to (x: unknown) => void.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Apr 17, 2024
@mwoenker
Copy link

mwoenker commented May 7, 2024

I think this is effectively a duplicate of this issue #49262

@gabritto gabritto added Duplicate An existing issue was already created and removed Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels May 21, 2024
@gabritto gabritto closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
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