admin管理员组文章数量:1122826
I am writing a typescript declaration file declarations.d.ts
that describes some interfaces and a global object. The declarations will be use to assist JavaScript developers that are writing script for an embedded v8 engine that offers global objects like the one being described.
There is a global variable Global
of interface type SomeGlobal
, which in turn has a property someType
of interface type SomeType
, and finally SomeType
has a callback
property of type function like (other:OtherType) => void
. Here is the entire file:
declarations.d.ts
interface OtherType
{
stringProperty: string;
}
interface SomeType
{
callback: (other:OtherType) => void;
}
interface SomeGlobal
{
someType: SomeType;
getSomeType(): SomeType;
}
declare var Global: SomeGlobal;
and the jsconfig.json
being used to ensure that code in main.js
can see these types:
{
"compilerOptions": {
"target": "es6",
"lib": ["es6"],
"strict": true
},
"include": [
"*.js",
"declarations.d.ts"
]
}
From here on, working in main.js
:
In VSCode when you attempt to assign the callback
property of SomeType
and open the parentheses to start building the arrow function like so:
Global.someType.callback = (
I would expect to see autocomplete help like callback(other: OtherType): void
, prompting me to complete the statement like:
Global.someType.callback = (other) => {/* do something*/};
But this is not what happens. If I hover over callback
VS will display the appropriate signature for the property (property) SomeType.callback: (other: OtherType) => void
, but inside the arrow function param list or funtion body, the other
param just shows up as type any
.
What's interesting is that if I go through a function call instead of a property:
Global.getSomeType().callback = (
Then there is correct function type inference for callback
and I get the intellisense autocomplete you'd expect.
Am I just missing something silly here?
I have tried searches of all kinds via Google and SO. I have tried various combinations of declaring the types as "type", "interface" or "class". I have tried declaring the types as classes and then just doing:
let testGlobal = new SomeGlobal();
// then
testGlobal.someType.callback = (other) => {};
still no dice, so it's not the way the global is declared.
本文标签:
版权声明:本文标题:javascript - In VSCode, why does function type inference break across a property accessor but not a function call - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299622a1930523.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论