دوره کامل Typescript
آموزش TypeScript #3
تعریف متغیرها و انواع داده
در TypeScript هنگام تعریف متغیرها باید نوع داده ای آنها را مشخص کنیم. در TypeScript پنج نوع داده ای وجود دارد که در زیر با ذکر مثال تعریف شده اند. مفاهیم ماژول، کلاس و تابع در پست بعدی به تشریح توضیح داده خواهند شد.
number : معادل نوع داده ای number در JavaScript است. برای ذخیره سازی اعداد صحیح و اعشاری استفاده میشود.
یک مثال:
class NumberTypeOfTypeScript { MyFunction() { var p: number; p = 1; var q = 2; var r = 3.33; alert("Value of P=" + p + " Value of q=" + q + " Value of r=" + r); } } window.onload = () =>{ var value = new NumberTypeOfTypeScript(); value.MyFunction(); }
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title>TypeScript HTML App</title> <link rel="stylesheet" href="app.css" type="text/css" /> <script src="app.js"></script> </head> <body> <h1>Number Type in TypeScript</h1> <div id="content"/> </body> </html>
string : معادل نوع داده ای رشته ای است و برای ذخیره سازی مجموعه ای از کاراکترها از نوع UTF-16 استفاده میشود.
یک مثال:
class StringTypeOfTypeScript { Myfunction() { var s: string; s="TypeScript" var empty = ""; var abc = "abc"; alert("Value of s="+ s+" Empty string="+ empty+" Value of abc ="+abc) ; } } window.onload = () =>{ var value = new StringTypeOfTypeScript(); value.Myfunction(); }
var StringTypeOfTypeScript = (function () { function StringTypeOfTypeScript() { } StringTypeOfTypeScript.prototype.Myfunction = function () { var s; s = "TypeScript"; var empty = ""; var abc = "abc"; alert("Value of s=" + s + " Empty string=" + empty + " Value of abc =" + abc); }; return StringTypeOfTypeScript; })(); window.onload = function () { var value = new StringTypeOfTypeScript(); value.Myfunction(); };
boolean: برای ذخیره سازی مقادیر true یا false میباشد.
مثال:
class booleanTypeofTypeScript { MyFunction() { var lie: bool; lie = false; var a = 12; if (typeof (lie) == "boolean" && typeof (a) == "boolean") { alert("Both is boolean type"); } if (typeof (lie) == "boolean" && typeof (a) != "boolean") { alert("lie is boolean type and a is not!") } else { alert("a is boolean type and lie is not!"); } } } window.onload =()=> { var access = new booleanTypeofTypeScript(); access.MyFunction(); }
var booleanTypeofTypeScript = (function () { function booleanTypeofTypeScript() { } booleanTypeofTypeScript.prototype.MyFunction = function () { var lie; lie = false; var a = 12; if(typeof (lie) == "boolean" && typeof (a) == "boolean") { alert("Both is boolean type"); } if(typeof (lie) == "boolean" && typeof (a) != "boolean") { alert("lie is boolean type and a is not!"); } else { alert("a is boolean type and lie is not!"); } }; return booleanTypeofTypeScript; })(); window.onload = function () { var access = new booleanTypeofTypeScript(); access.MyFunction(); };
مثال:
class NullTypeinTypeScript { MyFunction() { var p: number = null; var x = null; if (p== null) { alert("p has null value!"); } else { alert("p has a value"); } } } window.onload = () =>{ var value = new NullTypeinTypeScript(); value.MyFunction(); }
var NullTypeinTypeScript = (function () { function NullTypeinTypeScript() { } NullTypeinTypeScript.prototype.MyFunction = function () { var p = null; var x = null; if(p == null) { alert("p has null value!"); } else { alert("p has a value"); } }; return NullTypeinTypeScript; })(); window.onload = function () { var value = new NullTypeinTypeScript(); value.MyFunction(); };
undefined:معادل نوع undefined در Javascript است. اگر به یک متغیر مقدار اختصاص ندهید مقدار آن undefined خواهد بود.
مثال:
class UndefinedTypeOfTypeScript { Myfunction() { var p: number; var x = undefined; if (p == undefined && x == undefined) { alert("p and x is undefined"); } else { alert("p and c cannot undefined"); } } } window.onload = () =>{ var value = new UndefinedTypeOfTypeScript(); value.Myfunction(); }
var UndefinedTypeOfTypeScript = (function () { function UndefinedTypeOfTypeScript() { } UndefinedTypeOfTypeScript.prototype.Myfunction = function () { var p; var x = undefined; if(p == undefined && x == undefined) { alert("p and x is undefined"); } else { alert("p and c cannot undefined"); } }; return UndefinedTypeOfTypeScript; })(); window.onload = function () { var value = new UndefinedTypeOfTypeScript(); value.Myfunction(); };
ادامه دارد...
سلام
(نوع stub همانند فریم ورک mock میباشد )
تعریفی که از stup تو راهنماش اومده با مطلبی که شما ذکر کردید متفاوته
Martin Fowler’s article Mocks aren’t Stubs compares and contrasts the underlying principles of Stubs and Mocks. As outlined in Martin Fowler’s article, a stub provides static canned state which results in state verification of the system under test, whereas a mock provides a behavior verification of the results for the system under test and their indirect outputs as related to any other component dependencies while under test
Data architecture is an area in which the optimal degree of isolation for a SaaS application can vary significantly depending on technical and business considerations. Experienced data architects are used to considering a broad spectrum of choices when designing an architecture to meet a specific set of challenges, and SaaS is certainly no exception. We shall examine three broad approaches, each of which lies at a different location in the continuum between isolation and sharing
Dynamic types در Web API
TypeScript 4.2 منتشر شد
Let’s take a look at what’s in store for TypeScript 4.2!
- Smarter Type Alias Preservation
- Leading/Middle Rest Elements in Tuple Types
- Stricter Checks For The
in
Operator -
--noPropertyAccessFromIndexSignature
-
abstract
Construct Signatures - The
--explainFiles
Flag - Improved Uncalled Function Checks in Logical Expressions
- Destructured Variables Can Be Explicitly Marked as Unused
- Relaxed Rules Between Optional Properties and String Index Signatures
- Declare Missing Helper Function
- Breaking Changes
The missing scope - Tenant-Singleton
If a singleton is created once per application, you can probably guess that a tenant-singleton is created once per tenant.
So when might you need this scope? Think of any object that is expensive to create or needs to maintain state yet should be isolated for each tenant. Good examples would be NHibernate's Session Factory, RavenDB's Document Store or ASP.NET's Memory Cache.
- .NET Core is the future of .NET: If you’ve already started working with .NET Core, that’s great! If you’re starting a new project, you should consider .NET Core.
- .NET Framework will continue to be supported: If you have any existing applications on .NET Framework (Windows-only), you can keep those on .NET Framework.
- .NET Releases will become more predictable: Starting with .NET 5.0, there will be 1 major release every year, after which each even-numbered release (6.0, 8.0, etc) will come with LTS (Long-Term Support).