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

Debug Failure with strictFunctionTypes: type provided should not be a non-generic 'promise'-like #56509

Closed
frigus02 opened this issue Nov 22, 2023 · 4 comments Β· Fixed by #58547
Closed
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@frigus02
Copy link
Contributor

frigus02 commented Nov 22, 2023

πŸ”Ž Search Terms

type provided should not be a non-generic 'promise'-like

πŸ•— Version & Regression Information

  • This is a crash
  • This is the behavior in every version I tried: v5.2.2 and v5.3.2

⏯ Playground Link

Playground link

Note: Because this is a crash, the playground looks broken. The browser console has the stack trace.

πŸ’» Code

// @strict
type NotPromise<T> = T extends Thennable<unknown>
  ? T
  : T extends PromiseLike<unknown>
  ? never
  : T;

type Receiver<T> = (value: NotPromise<T>) => void;

class Thennable<T> {
  then(a: Receiver<T>) {}

  private handleResolve<TResult>(
    result: NotPromise<TResult> | Thennable<NotPromise<TResult>>,
    resolve: Receiver<TResult>,
  ) {
    if (result instanceof Thennable) {
      // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like.
      this.resolvePromise(result, resolve);
    }
  }

  private resolvePromise<TResult>(
    result: Thennable<TResult>,
    resolve: Receiver<TResult>,
  ) {}
}

πŸ™ Actual behavior

Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like.
    at createAwaitedTypeIfNeeded (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:76671:11)
    at getAwaitedType (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:76676:27)
    at getAwaitedTypeOfPromise (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:76554:28)
    at maybeAddMissingAwaitInfo (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:70872:13)
    at getSignatureApplicabilityError (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:70837:11)
    at resolveCall (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:71232:25)
    at resolveCallExpression (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:71633:12)
    at resolveSignature (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:72037:16)
    at getResolvedSignature (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:72059:18)
    at checkCallExpression (/test-ts-debug-assert-promise-like/node_modules/typescript/lib/tsc.js:72171:23)

at the node this.resolvePromise(result, resolve);

πŸ™‚ Expected behavior

No crash.

Additional information about the issue

Found this when migrating to ts.transpileModule. As far as I can tell it's triggered by 2 conditions, which all have to be true:

  • strictFunctionTypes: true
  • The type PromiseLike must not exist, e.g. by using noLib: true
@andrewbranch andrewbranch added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Nov 27, 2023
@andrewbranch andrewbranch added this to the TypeScript 5.4.0 milestone Nov 27, 2023
@typescript-bot
Copy link
Collaborator

The change between v4.7.4 and v4.8.4 occurred at a614119.

@jakebailey
Copy link
Member

FWIW I tested this and it's just always happened (as noted in the issue), so a bisect is gonna do something funky.

@andrewbranch
Copy link
Member

The crash doesn't show up in the playground in 4.7, at least not on page load

@jakebailey
Copy link
Member

Ah, I must have done something wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants