chenfengjw163 / vue-json-viewer

Simple JSON viewer component, for Vue.js 2 and support ssr
MIT License
544 stars 91 forks source link

Typescript module declaration is missing. #103

Open jkourou opened 1 year ago

jkourou commented 1 year ago

Hey

Typescript projects getting missing declaration for your module when importing it. You should add a declaration so we do not have to do it manually. Thank you!

Error:


Could not find a declaration file for module 'vue-json-viewer'. 'my-project/node_modules/vue-json-viewer/vue-json-viewer.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/vue-json-viewer` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-json-viewer';`
power721 commented 1 year ago

This maybe help: in src directory, create file vue-json-viewer.d.ts

declare module 'vue-json-viewer' {
    import { AllowedComponentProps, App, Component, ComponentCustomProps, VNodeProps } from 'vue'
    interface JsonViewerProps {
        value: Object | Array<any> | string | number | boolean;
        expanded: boolean;
        expandDepth: number;
        copyable: boolean | object;
        sort: boolean;
        boxed: boolean;
        theme: string;
        previewMode: boolean;
        timeformat: (value: any) => string
    }
    type JsonViewerType = JsonViewerProps & VNodeProps & AllowedComponentProps & ComponentCustomProps
    const JsonViewer: Component<JsonViewerType>
    export { JsonViewer }
    const def: { install: (app: App) => void }
    export default def
}
imvkmark commented 1 year ago

This maybe help: in src directory, create file vue-json-viewer.d.ts

declare module 'vue-json-viewer' {
    import { AllowedComponentProps, App, Component, ComponentCustomProps, VNodeProps } from 'vue'
    interface JsonViewerProps {
        value: Object | Array<any> | string | number | boolean;
        expanded: boolean;
        expandDepth: number;
        copyable: boolean | object;
        sort: boolean;
        boxed: boolean;
        theme: string;
        previewMode: boolean;
        timeformat: (value: any) => string
    }
    type JsonViewerType = JsonViewerProps & VNodeProps & AllowedComponentProps & ComponentCustomProps
    const JsonViewer: Component<JsonViewerType>
    export { JsonViewer }
    const def: { install: (app: App) => void }
    export default def
}

has this hint:

image
imvkmark commented 1 year ago

I use vue-json-pretty instead