Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Last active July 8, 2018 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/e138f1840302c79b4ffc5f961337c44b to your computer and use it in GitHub Desktop.
Save ORESoftware/e138f1840302c79b4ffc5f961337c44b to your computer and use it in GitHub Desktop.
stringifiable type with TS
export type Stringifiable = object | string | boolean | number | null;
export const stdMarker = 'gfy';
export const getJSONCanonical = function (v: Stringifiable, marker?: string) {
marker = marker || stdMarker;
return JSON.stringify({
[marker]: true,
value: v
});
};
getJSONCanonical(undefined); // no compilation error?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment