tsafe
GitHub
  • 👋What is tsafe?
  • ⚙️How to import
  • assert
  • Equals
  • id
  • is
  • objectKeys
  • exclude
  • isAmong
  • symToStr
  • ReturnType
  • Parameters
  • Param0
  • typeGuard
  • capitalize/uncapitalize
  • MethodNames
  • isPromiseLike
  • flip
  • objectEntries
  • objectFromEntries
  • UnionToIntersection
  • 🚧withDefaults
  • 📉UnpackPromise
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub

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"
PreviousisAmongNextReturnType

Last updated 6 months ago

Was this helpful?