Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Add Typescript definition file #23

Open
someone1 opened this issue Mar 28, 2018 · 5 comments
Open

[Suggestion] Add Typescript definition file #23

someone1 opened this issue Mar 28, 2018 · 5 comments
Labels

Comments

@someone1
Copy link

First off, thanks for the project!

Thought I'd share this and hope to make this package typescript friendly. Not sure if this is all that's required to get this working, but it did a lot for me. This assumes that the 'name' option is left at 'ls'. I still had to import like const Storage = require('vue-ls') - not sure if the fix is with a definitions file or modification of the shipped package.

import _Vue, { PluginFunction } from 'vue';

declare module 'vue/types/vue' {
  interface Vue {
    $ls: WebStorage;
  }

  interface VueConstructor {
    ls: WebStorage;
  }
}

declare class WebStorage {
  public length: number;

  constructor(storage: Storage);
  get(name: string, def?: any): any | null;
  set(name: string, value: any, expire?: number): void;
  key(index: number): string | null;
  remove(name: string): void;
  clear(): void;
  on(name: string, callback: Function): void;
  off(name: string, callback: Function): void;
}

declare interface StorageOptions {
  namespace?: string;
  name?: string;
  storage?: StorageTypes;
}

export enum StorageTypes {
  Session = 'session',
  Local = 'local',
  Memory = 'memory',
}

declare const _default: {
  install: PluginFunction<StorageOptions>;
};

export default _default;
@RobinCK
Copy link
Owner

RobinCK commented Mar 28, 2018

Thank you!
I will soon study the question and think about what can be done

@RobinCK RobinCK added the doc label Apr 19, 2018
@demiro
Copy link

demiro commented Feb 4, 2019

Yeah, TS support is important... I am getting erros while using it with TS

INE/timeline-vue/src/main.ts
3:21 Could not find a declaration file for module 'vue-ls'. 'C:/xx/_xx/xx-vue/node_modules/vue-ls/dist/vue-ls.js' implicitly has an 'any' type.
Try npm install @types/vue-ls if it exists or add a new declaration (.d.ts) file containing declare module 'vue-ls';

@mzhukovs
Copy link

@RobinCK any plans for this? would be much appreciated

@RobinCK
Copy link
Owner

RobinCK commented Jun 18, 2020

At the moment I don't have plans to add typings.
But PR is always welcome

@gopalakrishnanr-paypaycorp

@RobinCK Do you have any idea about below error?

Yes need typescript support, i have also facing that issue only

#23 (comment)

I did that now im not getting that issue after declaring like declare module 'vue-ls'; But below error still getting

147:9 Element implicitly has an 'any' type because expression of type '"$ls"' can't be used to index type BannerComponent

Property '$ls' does not exist on type 'BannerComponent'. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants