From 6c2f1c7132e2e8c321aeefbb06f9ce31ea92d13e Mon Sep 17 00:00:00 2001 From: Vishakha Tak <47105030+vc-vishakha@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:08:55 +0530 Subject: [PATCH 1/2] Added unknown type in typescript.html.markdown --- typescript.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/typescript.html.markdown b/typescript.html.markdown index 24d1db10..9d65629b 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -37,6 +37,11 @@ let notSure: any = 4; notSure = "maybe a string instead"; notSure = false; // okay, definitely a boolean +// When we are not sure about the type, and don't want to use "any", we can use "unknown" type +let unknownVariable: unknown = 'Abc'; // we don't fully know yet the type +unknownVariable = 1234; // possible +const someVariable: string = unknownVariable; // Invalid; we can't assign unknownVariable to any other type (without an explicit assertion), unlike any + // Use const keyword for constants const numLivesForCat = 9; numLivesForCat = 1; // Error From 234f4f52bb3516b31b9863f6f2fb7740905082f1 Mon Sep 17 00:00:00 2001 From: Vishakha Tak <47105030+vc-vishakha@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:21:41 +0530 Subject: [PATCH 2/2] Update typescript.html.markdown with appropriate example names --- typescript.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript.html.markdown b/typescript.html.markdown index 9d65629b..d351615b 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -38,8 +38,8 @@ notSure = "maybe a string instead"; notSure = false; // okay, definitely a boolean // When we are not sure about the type, and don't want to use "any", we can use "unknown" type -let unknownVariable: unknown = 'Abc'; // we don't fully know yet the type -unknownVariable = 1234; // possible +let unknownVariable: unknown = 'Some string'; // we don't fully know yet the type +unknownVariable = 2; // possible const someVariable: string = unknownVariable; // Invalid; we can't assign unknownVariable to any other type (without an explicit assertion), unlike any // Use const keyword for constants