tsafe
Search…
⌃K
Links

symToStr

Get the name of a symbol as typed string.
import { symToStr } from "tsafe/symToStr";
​
declare const foo: any;
​
//str is of type "foo" and str === "foo"
const str = symToStr({ foo });

Without symToStr

export const myFunctionX = () => {};
​
export const name = "myFunctionX";
If you happen to rename `myFunctionX` into something else it is easy to forget to rename the exported name as well.

With symToStr

import { symToStr } from "tsafe/symToStr";
​
export const myFunctionX = () => {};
​
export const name = symToStr({ myFunctionX });
// ^name is of type "myFunctionX"
Last modified 2mo ago