Skip to content

Instantly share code, notes, and snippets.

@chrishasz
Last active January 11, 2022 19:27
Show Gist options
  • Select an option

  • Save chrishasz/d39ee076a863165d1696581a0eccb97a to your computer and use it in GitHub Desktop.

Select an option

Save chrishasz/d39ee076a863165d1696581a0eccb97a to your computer and use it in GitHub Desktop.
A type-generic class to read and write project or extension-wide data in VSCode's durable key-value storage
'use strict';
import { Memento } from "vscode";
export class LocalStorageService {
constructor(private storage: Memento) { }
public getValue<T>(key : string) : T{
return this.storage.get<T>(key, null);
}
public setValue<T>(key : string, value : T){
this.storage.update(key, value );
}
}
@pccai
Copy link

pccai commented Aug 26, 2021

public getValue<T>(key : string) : T{
    return this.storage.get<T>(key,<T><any> "");
}

null change to ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment