Skip to content

genki/ref

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ref

The ref object for TypeScript

Install

npm insgall @s21g/ref

Usage

As a variable to refer the property of the state object with checking type and existance.

import ref { Ref, getRef, setRef } from "@s21g/ref"
const state = {name:"Taro", age:20};
const nameRef:Ref<string> = ref({name:state});
const name = getRef(nameRef);
setRef(nameRef, "Jiro");

As an argument to refer the property of the state object with checking type and existance.

const foo = <V,K extends string,S>(
  ref:Ref<V,K,S>,
  value:V,
) => {
  setRef(ref, value);  
};
const state:{count:number, name:string} = {count: 0, name: "foo"};
foo({count:state}, 2);
getRef({count:state})) // => 2

Playground: https://stackblitz.com/edit/typescript-demo-ugx7jw?devToolsHeight=33&file=index.ts

About

ref object for TypeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published