Comments (6)
I gave this a try with a different syntax for overloads:
declare function bar(
...args: [arg0: string, arg1: number, arg2: boolean] | [arg0: number, arg1: boolean, arg2: string] | [arg0: boolean, arg1: string, arg2: number]
): void;
This example is even worse. The editor correctly finds the 3 overloads, but bar(5,
and bar(5, )
both fail to resolve to the second overload.
from typescript.
The difference lies in how callIsIncomplete
gets computed in both scenarios:
https://github.dev/microsoft/TypeScript/blob/0b71b81d7d053a3acd379ff49550b3c67f9ce3cd/src/compiler/checker.ts#L33830-L33831
and how, based on that, the version without parenthesis returns true
from hasCorrectArity
:
https://github.dev/microsoft/TypeScript/blob/0b71b81d7d053a3acd379ff49550b3c67f9ce3cd/src/compiler/checker.ts#L33845-L33849
from typescript.
I don't think it's really possible to define what the "correct" overload is for an argument set that doesn't match anything. When the parens are still open it makes sense to pretend the future params might be there, but when it's closed, well, who can say what kind of mistake you're making. For example, if there's an overload of one parameter of type "foo"
and you wrote func("oo")
it seems like we should show you "foo"
rather than some other possible overload
from typescript.
@RyanCavanaugh not really sure I agree with you. "oo" doesn't match "foo", so why would you show me "foo"?
Overload matching should be best effort matching, no?
In my example, the argument list isn't done, because the comma is indicating I intend to add more arguments.
Not adding another argument is a syntax error. Removing the comma is a compiler error. In either of these choices, it's an invalid call. Why complicate things by not even telling me what the next argument should be?
from typescript.
In cases where you have trailing commas in an argument list, you'd have a compiler error if you couldn't find the right overload, so I'd agree here that it wouldn't matter which overload you show.
declare function foo(x: number): void;
declare function foo(x: "foo"): void;
foo(
"oo", // error: No overload matches this call.
)
But this is a specifically talking about functions with one parameter.
The main issue I'm trying to outline in my example is that there are multiple parameters, with a correct first argument, yet the overload is not resolved/narrowed.
from typescript.
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- ESNext Set methods HOT 1
- isolatedDeclarations should not have warning for functions that have no return statements HOT 4
- Trivia ownership documentation seems to be incorrect
- `--isolatedDeclarations` allows generator functions HOT 1
- Allow `--noCheck` on the CLI with top-level `--build`
- Union in template literal simplifying unexpectedly HOT 5
- Default import from an ESM package into a CommonJS project with esModuleInterop is faulty HOT 3
- Watch cannot handle large amount of file changes HOT 1
- generator next type should be inferred as union (instead of intersection) of yields' types OR just unknown
- Elementwise elaboration fails to be found for properties mixed with incompatible index signatures using intersections
- Error when accessing properties on `globalThis` with the same name of a global variable HOT 2
- [NewErrors] 5.5.0-dev.20240428 vs 5.4.5 HOT 49
- Private class properties prevent `Readonly` type inference HOT 2
- [ServerErrors][TypeScript] 5.5.0-dev.20240428 HOT 12
- [ServerErrors][JavaScript] 5.5.0-dev.20240428 HOT 9
- Strange runtime caching bug involving `as const` and `const T` generic HOT 1
- When relatively importing a `.d.ts` file in a declaration file, TypeScript loads a `.ts` file instead HOT 7
- Calling decorators with @ loses type safety with function as argument HOT 2
- Include error maps in the typescript libraries for web apis to give developers easy access to potential thrown exceptions HOT 6
- jsdoc @type does not resolve a type HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.