Yon*_*uan 6 intellisense typescript visual-studio-code typescript-typings
给定此代码,例如:
// src/index.ts
export function hello(props: {
type: 'boolean';
params: {
bool: boolean;
}
}): void;
export function hello(props: {
type: 'string';
params: {
str: string;
num: number;
}
}): void;
export function hello(props: {
type?: any;
params?: any;
}): void {
console.log(props);
}
// index.ts
import { hello } from './src';
hello({
type: 'string', /* autosuggests 'string' and 'boolean' */
params: {
/* autosuggests `str` and `num` (not `bool`) as property options, which is correct and expected */
}
})
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常。但是,当我将相同的内容传输到.js文件和.d.ts文件中时,相同的声明不再起作用:
// src/index.d.ts
export function hello(props: {
type: 'boolean';
params: {
bool: boolean;
}
}): void;
export function hello(props: {
type: 'string';
params: {
str: string;
num: number;
}
}): void;
export function hello(props: {
type?: any;
params?: any;
}): void;
// src/index.js
export function hello(props){
console.log(props);
}
// index.js
import { hello } from './src';
/* CTRL + clicking `hello` points me to the `src/index.d.ts` file, which is correct */
hello({
type: 'string', /* does not autosuggest anything */
params: {
/* does not autosuggest anything */
}
})
Run Code Online (Sandbox Code Playgroud)
谁能指出我正确的方向?
| 归档时间: |
|
| 查看次数: |
164 次 |
| 最近记录: |