Comments (5)
The generated function has SignatureFlags.IsUntypedSignatureInJSFile
assigned to it. So its min argument count gets computed as 0. Based on that calls without any arguments are allowed as the provided number of arguments (0 here) satisfies the min argument count.
Currently, this flag is not assigned to signatures coming from JS files when the function has either @param
tag or when the function itself is typed using @type
. For that reason, you end with the same problem when the function is contextually-typed using @satisfies
:
/** @satisfies {(arg: string) => void} */
const func = function func(param) { };
func() // oops
Related(ish) case to the @satisfies
can be found here
from typescript.
@kungfooman That's because the parameter itself is, in fact, optional:
function func(/** @type {string} */ param) {}
/**
* @typedef {typeof func} Func
* @typedef {Func extends (...args: infer P) => any ? P : never} FuncParam
*/
func(); // not an error
I don't know why it's treated as optional, but the inference result is correct.
from typescript.
Funny behaviour, and why does it work somewhat better in only one file: Playground
function func(/** @type {string} */ param) {}
/**
* @typedef {typeof func} Func
* @typedef {Func extends (...args: infer P) => any ? P : never} FuncParam
*/
Result: type FuncParam = [param?: string]
(it shouldn't be optional)
from typescript.
I don't know why it's treated as optional, but the inference result is correct.
If we turn on strictNullChecks
it's suddenly never
again 😅
IMO it should only ever be considered optional if we use the Google Closure syntax:
function func(/** @type {string=} */ param) {}
(=
after string
)
from typescript.
Thank you for the playground links! Reproduces the problem nicely.
In the non-optional cases above, the tooltip hover still thinks that func
is a function with a non-optional (param: string)
parameter. Which seems correct. Later still having param
be optional seems weird to me too, but maybe that's how optionality works 🤷
In addition, both the infer
and func()
remain inconsistent with how @param
works (which is how I expect, in fact):
/** @param {string} param */
function func(param) {}
func() // error
and FuncParam
as above is [param: string]
. Playground link
from typescript.
Related Issues (20)
- Crashes on transform and parse (from assertion/debug failures) HOT 4
- Object circular assignment never error HOT 2
- Only resolve source return type when actually needed during inference when generic is used HOT 2
- Target signature provides too few arguments. Expected 1 or more, but got 0 HOT 1
- Convert params to destructed object: Cannot apply refactoring HOT 2
- getPasteEdits returns edits even when no imports are added
- getPasteEdits returns wrong range for primary edit
- Some long function return expressions no longer evaluated in 5.5 HOT 3
- Generic is "`any`-like" for relational operators HOT 3
- inherit interface/type block comment HOT 2
- JSDoc: property access within static initialization block of @extends annotated class from different file
- Isolated Declarations in TS 5.5: State of the feature
- Isolated declarations quick fix suggests `boolean` return type for predicates HOT 2
- Is the "Roadmap" wiki page still maintained? HOT 3
- Typescript 5.5 is not working with yarn v4 and nodeLinker pnp, it forces switching to nodeLinker node-modules HOT 4
- update Object.values and Object.entries docs to mention they look only at own properties HOT 1
- `@import` JSDoc tag doesn't seem to account for `resolution-mode` import attribute in TS v5.5.2 HOT 1
- `/// <reference lib` is stripped out of `d.ts` file HOT 2
- HookWebpackError: Maximum call stack size exceeded in Release 5.5.2 HOT 1
- TS 5.5 type guards overly strict in some cases HOT 3
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.