Typescript vscode可以生成类型定义吗?

Typescript vscode可以生成类型定义吗?,typescript,visual-studio-code,Typescript,Visual Studio Code,我一直在使用一种技巧来快速打字: 我根据实际数据进行打字: const ParcelFeatureTypeInstance = {"displayFieldName":"NAMECO","fieldAliases":{"PIN":"PIN / Tax Map #","OWNAM1":"Owner Name(MixedCase)",...}; type ParcelFeatureType = typeof ParcelFeatureTypeInstance; 但我想更进一步,然后将鼠标悬停在类

我一直在使用一种技巧来快速打字:

我根据实际数据进行打字:

const ParcelFeatureTypeInstance = {"displayFieldName":"NAMECO","fieldAliases":{"PIN":"PIN / Tax Map #","OWNAM1":"Owner Name(MixedCase)",...};
type ParcelFeatureType = typeof ParcelFeatureTypeInstance;
但我想更进一步,然后将鼠标悬停在类型上时打开的弹出窗口中复制实际的类型定义,但定义不完整:

const ParcelFeatureTypeInstance: {
    displayFieldName: string;
    fieldAliases: {
        PIN: string;
        OWNAM1: string;
        OWNAM2: string;
        STREET: string;
        CITY: string;
        STATE: string;
        ZIP5: string;
        NAMECO: string;
        POWNNM: string;
        DEEDDATE: string;
        CUBOOK: string;
        ... 23 more ...;
        OBJECTID: string;
    };
    geometryType: string;
    spatialReference: {
        ...;
    };
    fields: ({
        ...;
    } | {
        ...;
    })[];
    features: {
        ...;
    }[];
}

有没有办法获得完整的定义?

您可以声明并发出
.d.ts
文件

试试这个

在example.ts文件中,输入常量和类型:

const ParcelFeatureTypeInstance = {"displayFieldName":"NAMECO","fieldAliases":{"PIN":"PIN / Tax Map #","OWNAM1":"Owner Name(MixedCase)"}};
export type ParcelFeatureType = typeof ParcelFeatureTypeInstance;
在tsconfig.json中,至少放置:

{
  "compilerOptions": {
    "declaration": true
  }
}
然后,运行编译器:

tsc -p tsconfig.json

您将获得一个新文件
example.d.ts
,其中包含常量和变量的类型声明

伟大的解决方案!虽然不如复制想法好,但它可以在一个独立的项目中完成。美好的