Created
November 26, 2018 10:38
-
-
Save ragmha/d05f00463ae2842ea0bfc972011f840d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Pizza = { name: string; toppings: number }; | |
const pizza: Pizza = { name: 'Blazing Inferno', toppings: 5 }; | |
const serialized = JSON.stringify(pizza); | |
function getNameFromJSON(obj: string) { | |
// return (<Pizza>JSON.parse(obj)).name; | |
return (JSON.parse(obj) as Pizza).name; | |
} | |
getNameFromJSON(serialized); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment