Skip to content

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
BrightBoost committed Jun 8, 2024
1 parent 4bde766 commit 024990d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let jsonString: string = '{"name": "John", "age": 30}';

// We know the structure of JSON, assert the type
let userInfo: { name: string; age: number } = JSON.parse(jsonString) as { name: string; age: number };

console.log(userInfo.name); // Outputs: John
console.log(userInfo.age); // Outputs: 30
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let someValue: any = "this is a string";

let strLength: number = (someValue as string).length;

console.log(strLength); // Outputs the length of "someValue"

let someValue2: any = "this is another string";

let strLength2: number = (<string>someValue).length;

console.log(strLength2); // Outputs the length of "someValue"

0 comments on commit 024990d

Please sign in to comment.