Skip to content

Instantly share code, notes, and snippets.

View difosfor's full-sized avatar

Peter Paul Elfferich difosfor

  • Ex Machina
  • Amsterdam
View GitHub Profile
@difosfor
difosfor / TypedStorage.ts
Created July 6, 2020 15:03
Typed localStorage
export class TypedStorage<Items> {
private prefix: string;
constructor(prefix: string) {
this.prefix = prefix;
}
public delete<Key extends keyof Items>(key: Key) {
const value = this.get(key);
const prefixedKey = this.getPrefixedKey(key);
@difosfor
difosfor / my-element.ts
Last active September 21, 2023 02:25
Typed LitElement events
import { customElement, LitElement } from 'lit-element';
type UnpackCustomEvent<T> = T extends CustomEvent<infer U> ? U : never;
// Define custom event types and details here
interface CustomEventMap {
/**
* Dispatched when an error occurs.
*/
'my-error': CustomEvent<{ error: Error }>;