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

Function Generic is unknown if argument has NoInfer<Generic> but returns the Generic #60922

Open
JeanMeche opened this issue Jan 6, 2025 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@JeanMeche
Copy link
Contributor

πŸ”Ž Search Terms

  • Generic
  • NoInfer
  • Unknown

πŸ•— Version & Regression Information

Still the case in the latest 5.7.2.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBAE2AYwDYEMrDgMwK4B2yMAlhAXKiQQNbAIDKJA5geqgDwMA0cAIgD4AFBDClyAZwBccAN4AoOErgSIeKMmAyhASjgBeAXAYBuRcuQQAtmDwx04gttXrNMgHIQAkgRzAoHIJ6hvxmAL46Mnxm8pYEEvASLGyoBpTUdIzJ7EIKyipqGlpwugZGAMzc5kqWNnYOZE4lEsEVcPIR8vJAA

πŸ’» Code

export declare function linkedSignal<S, D>(options: {
    source: () => S;
    computation: (source: NoInfer<D>) => D;
}): D;

const signal = linkedSignal({
    source: () => 3,
    computation: (s) => 3 
})

πŸ™ Actual behavior

signal is unknown

πŸ™‚ Expected behavior

signal is number

Additional information about the issue

I wasn't sure, but it could be a duplicate of #60544.

@Andarist
Copy link
Contributor

Andarist commented Jan 6, 2025

This, indeed, looks like a simpler version of #60544

I don't quite see how this could be implemented beyond some very basic support for a small set of scenarios. The return type of a function very often depends (even if indirectly) on its parameters types. Like, how would you determine what D should be here?

const signal = linkedSignal({
    source: () => 3,
    computation: (s) => s
})

Would unknown be a satisfiable inference here? What about this one?

const signal = linkedSignal({
    source: () => 3,
    computation: (s) => {
      return Math.random() > 0.5 > 1 : s;
    }
})

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 6, 2025
@JeanMeche
Copy link
Contributor Author

I think I get your point.

number | unknown narrows down to unknown, so unknown is the reseanable inference.

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

3 participants