Skip to content

Wrong elementwise error location on optional object property that allows arrays too #57541

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

Open
Andarist opened this issue Feb 26, 2024 · 0 comments · May be fixed by #57537
Open

Wrong elementwise error location on optional object property that allows arrays too #57541

Andarist opened this issue Feb 26, 2024 · 0 comments · May be fixed by #57537
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@Andarist
Copy link
Contributor

🔎 Search Terms

error location elementwise elaboration array optional object

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240225#code/C4TwDgpgBAyglgOwOYBsIHkBOBBTmCGIAPACoB8UAvFCVAD5SYT4AmA9giiDQNoC6AbgBQQ0JCgAFTGwBucFhBbYAxsDaYqUAN5CoUAM6ZlALgPBMiJML2IwAV2AB+U3YQBrBGwDuCYQF9hUXBoAFl8ZQALRAgAYQ4AMzgkUhU1TH0oCAAPYAgEFgypWXlFVPUKah0bBBk2NwhnWEs0LFwCYhIy9LJ-QIVlFHwmKHjXVTgOAwhgOzAU1XUM7Nz8wuk5BSUFzDIACgBKUyqoZSZ8XLDI6NNd5QSk00uohFj75M7t-TJ9qgpa+V6In001mRC0BiMpgARPFppEAKrAzBQgRQWwOUz6cyWKB+Pb7AB0p2YF3Czwgu2OiFq9SOuj0EJMUBhcIiiIgyIANPTqvZgKYAIwABm5ej83L8+2EQA

💻 Code

type SingleOrArray<T> = T | readonly T[];

type ProvidedActor = {
  src: string;
  input?: unknown;
};

type MachineConfig<TActors extends ProvidedActor> = {
  invoke?: SingleOrArray<TActors>;
};

declare function setup<TActors extends ProvidedActor>(): {
  createMachine: (config: MachineConfig<TActors>) => void;
};

setup<{ src: "fetchUser"; input: string }>().createMachine({
  invoke: {
    src: "fetchUser",
    input: 10,
  },
});

🙁 Actual behavior

invoke property gets highlighted

🙂 Expected behavior

input property should get highlighted as it's the one that it's not correct and it's more specific than invoke

Additional information about the issue

we can observe the error location to change when:

  1. we remove optionality from invoke
  2. we make the provided type argument a union
@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Feb 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants