TypeScript for Testers
This page shows the types that a tester needs, how tsc checks them, and how to run that check next to Node.js and Playwright.
6 min read6 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 9 sources9টি সোর্স · updated Nov 2026আপডেট: Nov 2026
strict catches the missing valuestrict মিসিং ভ্যালু ধরে ফেলে
Turn strictNullChecks on and see a hidden bug turn into a compile error.strictNullChecks চালু করুন আর দেখুন লুকানো bug একটা কম্পাইল এরর হয়ে যায়।
You’ll learnআপনি শিখবেন
- How a ? field may be missing? field কীভাবে না থাকতে পারে
- Node runs code without type checksNode type check ছাড়াই কোড চালায়
- What strict adds for nullnull-এর জন্য strict কী যোগ করে
- How narrowing fixes the errornarrowing কীভাবে এরর সারায়
- Why any hides bugsany কেন bug লুকায়
What it is
TypeScript has all the features of JavaScript, with a type system on top of them Source 1সোর্স 1. A static type system predicts what the code is expected to do before it runs Source 2সোর্স 2, and a static type-checker like TypeScript helps find bugs before the code runs Source 2সোর্স 2. In many cases TypeScript can infer the types by itself, even when the code leaves them out Source 2সোর্স 2.
The checker is tsc, the TypeScript compiler Source 2সোর্স 2. Type annotations, such as person: string on a parameter, describe what types of values a function can be called with Source 2সোর্স 2. Type annotations never change the runtime behaviour of a program Source 2সোর্স 2.
For a tester, this matters because the test tools run TypeScript directly. Playwright reads a TypeScript test, transforms it to JavaScript, and runs it Source 8সোর্স 8. Node.js can run a TypeScript file too Source 7সোর্স 7. Read JavaScript for Testers first.
সহজ English
TypeScript is JavaScript plus types Source 1সোর্স 1. Types let a tool find mistakes before the code runs Source 2সোর্স 2. Often TypeScript works out the types by itself, even when you leave them out Source 2সোর্স 2.
The tool that checks is called tsc Source 2সোর্স 2. A type annotation, like person: string, says what kind of value a function takes Source 2সোর্স 2. Type annotations never change what the program does when it runs Source 2সোর্স 2.
This matters for testers because test tools run TypeScript directly. Playwright turns a TypeScript test into JavaScript and runs it Source 8সোর্স 8. Node.js can run a TypeScript file too Source 7সোর্স 7. Read JavaScript for Testers first.
বাংলা ব্যাখ্যা
TypeScript-এ JavaScript-এর সব feature আছে, আর তার ওপরে একটা type system Source 1সোর্স 1। Static type system কোড চালানোর আগেই অনুমান করে, কোডটা কী করবে বলে আশা করা যায় Source 2সোর্স 2, আর TypeScript-এর মতো static type-checker কোড চালানোর আগেই bug খুঁজে পেতে সাহায্য করে Source 2সোর্স 2। অনেক ক্ষেত্রে type লেখা না থাকলেও TypeScript নিজেই type বের করে নিতে পারে Source 2সোর্স 2।
Check করে tsc, অর্থাৎ TypeScript compiler Source 2সোর্স 2। Type annotation, যেমন parameter-এ person: string, বলে দেয় function-টা কোন type-এর value দিয়ে call করা যায় Source 2সোর্স 2। Type annotation কখনো program চলার সময়ের আচরণ বদলায় না Source 2সোর্স 2।
টেস্টারের জন্য এটা জরুরি, কারণ টেস্ট টুলগুলো TypeScript সরাসরি চালায়। Playwright একটা TypeScript টেস্ট পড়ে, JavaScript-এ রূপান্তর করে চালায় Source 8সোর্স 8। Node.js-ও TypeScript file চালাতে পারে Source 7সোর্স 7। আগে JavaScript for Testers পড়ে নিন।
How it works
- Type aliases and interfaces. A type alias is a name for any type Source 3সোর্স 3. An interface is another way to name an object type Source 3সোর্স 3.
- Unions and literal types. A union type is made from two or more types, and a value may be any one of them Source 3সোর্স 3. A literal type names one exact string or number Source 3সোর্স 3. Combined in a union, literals express a set of known values, such as
'tester' | 'developer'Source 3সোর্স 3. - Optional properties. A
?after the property name makes the property optional Source 3সোর্স 3. readonly. TypeScript does not let you write to areadonlyproperty during type-checking, but nothing changes at run time Source 4সোর্স 4.- Narrowing. TypeScript understands checks such as
typeofand uses them to narrow a type inside a branch Source 5সোর্স 5. - Generics. A generic component works over many types rather than a single one Source 9সোর্স 9.
any. A value of typeanyis not type-checked Source 3সোর্স 3. ThenoImplicitAnyflag makes an implicitanyan error Source 3সোর্স 3.- Null checks. By default,
nullandundefinedare assignable to any other type Source 2সোর্স 2. WithstrictNullCheckson, you must test for them before you use a method or property of the value Source 3সোর্স 3. Thestrictflag turns on the whole family of strict checks Source 6সোর্স 6; the two biggest arenoImplicitAnyandstrictNullChecksSource 2সোর্স 2.
সহজ English
- Names for types. A type alias gives a name to any type Source 3সোর্স 3. An interface names the shape of an object Source 3সোর্স 3.
- A closed list. A union type says "one of these" Source 3সোর্স 3. With exact values, like
'tester' | 'developer', it gives a set of known values Source 3সোর্স 3. - Optional fields. A
?after a field name means the field may be missing Source 3সোর্স 3. readonly. The checker stops you from writing to areadonlyfield. The running program does not change Source 4সোর্স 4.- Narrowing. After a check such as
typeof, TypeScript knows the type inside that branch Source 5সোর্স 5. - Generics. A generic piece of code works with many types, not just one Source 9সোর্স 9.
any.anyswitches the check off for that value Source 3সোর্স 3. ThenoImplicitAnyflag turns a hiddenanyinto an error Source 3সোর্স 3.- Missing values. By default,
nullandundefinedcan go anywhere Source 2সোর্স 2. WithstrictNullCheckson, you must check for them before you use a method or property of the value Source 3সোর্স 3.strictturns on all the strict checks at once Source 6সোর্স 6, and the two biggest arenoImplicitAnyandstrictNullChecksSource 2সোর্স 2.
বাংলা ব্যাখ্যা
- Type alias আর interface। Type alias যেকোনো type-এর একটা নাম Source 3সোর্স 3। Interface হলো object type-এর নাম দেওয়ার আরেকটা উপায় Source 3সোর্স 3।
- Union আর literal type। Union type দুই বা তার বেশি type দিয়ে তৈরি, আর value হতে পারে তাদের যেকোনো একটা Source 3সোর্স 3। Literal type একটা নির্দিষ্ট string বা number-এর নাম Source 3সোর্স 3। Literal-গুলো union-এ মেলালে জানা value-এর একটা নির্দিষ্ট set পাওয়া যায়, যেমন
'tester' | 'developer'Source 3সোর্স 3। - Optional property। Property-র নামের পরে
?দিলে property-টা optional হয় Source 3সোর্স 3। readonly। Type-checking-এর সময় TypeScriptreadonlyproperty-তে লিখতে দেয় না, কিন্তু চলার সময় কিছুই বদলায় না Source 4সোর্স 4।- Narrowing। TypeScript
typeof-এর মতো চেক বোঝে, আর সেটা দিয়ে একটা branch-এর ভেতরে type সরু করে আনে Source 5সোর্স 5। - Generic। Generic component একটা type নয়, অনেক type নিয়ে কাজ করে Source 9সোর্স 9।
any।anytype-এর value type-check হয় না Source 3সোর্স 3।noImplicitAnyflag অপ্রকাশ্যany-কে error বানায় Source 3সোর্স 3।- Null check। ডিফল্টভাবে
nullআরundefinedযেকোনো type-এ বসানো যায় Source 2সোর্স 2।strictNullChecksচালু থাকলে value-র method বা property ব্যবহারের আগে এগুলোর জন্য চেক করতে হয় Source 3সোর্স 3।strictflag পুরো strict check-এর পরিবারটা চালু করে Source 6সোর্স 6; এর সবচেয়ে বড় দুটো হলোnoImplicitAnyআরstrictNullChecksSource 2সোর্স 2।
Try it
Save this as users.ts. You need Node.js 22.18 or newer (type stripping is on by default from v22.18.0 and v23.6.0 Source 7সোর্স 7) and TypeScript (npm install -D typescript).
type Role = 'tester' | 'developer';
interface User {
name: string;
role: Role;
email?: string;
}
function label(user: User): string {
return `${user.name} (${user.role})`;
}
function emailDomain(user: User): string {
if (user.email === undefined) return 'none';
return user.email.split('@')[1];
}
const users: User[] = [
{ name: 'Asha', role: 'tester' },
{ name: 'Rafi', role: 'developer', email: 'rafi@example.com' },
];
console.log(users.map(label));
console.log(users.map(emailDomain));- Check it with
npx tsc --noEmit --strict users.ts. It finds no errors. - Run it with
node users.ts. By default, Node.js runs TypeScript files that contain only erasable TypeScript syntax Source 7সোর্স 7. It prints[ 'Asha (tester)', 'Rafi (developer)' ]and[ 'none', 'example.com' ]. - Change Asha's role to
'manager'.tscnow reportsType '"manager"' is not assignable to type 'Role'.Butnode users.tsstill runs and printsAsha (manager). Node.js replaces the TypeScript syntax with whitespace and does no type checking Source 7সোর্স 7. - Put the role back and delete the
if (user.email === undefined)line.tscreports'user.email' is possibly 'undefined'.nodenow crashes withTypeError: Cannot read properties of undefined (reading 'split'). This is the bug that the null check exists to catch Source 3সোর্স 3.
সহজ English
Save this as users.ts. You need Node.js 22.18 or newer (type stripping is on by default from v22.18.0 and v23.6.0 Source 7সোর্স 7) and TypeScript (npm install -D typescript).
type Role = 'tester' | 'developer';
interface User {
name: string;
role: Role;
email?: string;
}
function label(user: User): string {
return `${user.name} (${user.role})`;
}
function emailDomain(user: User): string {
if (user.email === undefined) return 'none';
return user.email.split('@')[1];
}
const users: User[] = [
{ name: 'Asha', role: 'tester' },
{ name: 'Rafi', role: 'developer', email: 'rafi@example.com' },
];
console.log(users.map(label));
console.log(users.map(emailDomain));- Check it:
npx tsc --noEmit --strict users.ts. No errors. - Run it:
node users.ts. By default, Node.js runs TypeScript files that contain only erasable TypeScript syntax Source 7সোর্স 7. You see[ 'Asha (tester)', 'Rafi (developer)' ]and[ 'none', 'example.com' ]. - Change Asha's role to
'manager'.tscsays"manager"is not allowed. Butnodestill runs it and printsAsha (manager), because Node.js does not check types Source 7সোর্স 7. - Put the role back, and delete the
if (user.email === undefined)line.tscwarns thatuser.emailmay beundefined.nodenow crashes with aTypeError. The null check is there to catch exactly this Source 3সোর্স 3.
বাংলা ব্যাখ্যা
এটা users.ts নামে সেভ করুন। Node.js 22.18 বা নতুন (type stripping ডিফল্টভাবে চালু v22.18.0 ও v23.6.0 থেকে Source 7সোর্স 7) আর TypeScript লাগবে (npm install -D typescript)।
type Role = 'tester' | 'developer';
interface User {
name: string;
role: Role;
email?: string;
}
function label(user: User): string {
return `${user.name} (${user.role})`;
}
function emailDomain(user: User): string {
if (user.email === undefined) return 'none';
return user.email.split('@')[1];
}
const users: User[] = [
{ name: 'Asha', role: 'tester' },
{ name: 'Rafi', role: 'developer', email: 'rafi@example.com' },
];
console.log(users.map(label));
console.log(users.map(emailDomain));npx tsc --noEmit --strict users.tsদিয়ে check করুন। কোনো error নেই।node users.tsদিয়ে চালান। ডিফল্টভাবে Node.js সেই TypeScript file চালায়, যেখানে শুধু মুছে ফেলা যায় এমন (erasable) TypeScript syntax আছে Source 7সোর্স 7। Output:[ 'Asha (tester)', 'Rafi (developer)' ]আর[ 'none', 'example.com' ]।- Asha-র role বদলে
'manager'করুন।tscএবার বলবেType '"manager"' is not assignable to type 'Role'.কিন্তুnode users.tsতবুও চলে আরAsha (manager)দেখায়। Node.js TypeScript syntax-কে whitespace দিয়ে বদলে দেয়, কোনো type check করে না Source 7সোর্স 7। - Role আগের মতো করে
if (user.email === undefined)লাইনটা মুছে দিন।tscবলবে'user.email' is possibly 'undefined'.আরnodeএবারTypeError: Cannot read properties of undefined (reading 'split')দিয়ে crash করবে। Null check ঠিক এই bug ধরার জন্যই আছে Source 3সোর্স 3।
How a tester uses it
- Run
tscnext to the tests. Playwright does not check types, and it runs tests even when there are non-critical compile errors. Its docs recommend that you run the TypeScript compiler alongside it Source 8সোর্স 8. In CI, that isnpx tsc -p tsconfig.json --noEmitbeforenpx playwright testSource 8সোর্স 8. - Watch while you write. Locally,
npx tsc -p tsconfig.json --noEmit -wkeeps checking as you save Source 8সোর্স 8. - Type the API responses. An interface declaration describes the shape of an object Source 1সোর্স 1: write one for each response body that a test reads. Reading a field that does not exist gives
undefinedin JavaScript, but an error in TypeScript Source 2সোর্স 2, so a typo in a field name fails the check. - Close the lists. A union of literal types, such as the allowed roles or statuses, rejects any value that is not on the list Source 3সোর্স 3.
- Mark the missing. Optional properties show which fields can be absent Source 3সোর্স 3, and
strictNullChecksmakes the code check for them Source 3সোর্স 3. - Reuse helpers. A generic component can work over a variety of types rather than a single one Source 9সোর্স 9.
সহজ English
- Run
tscnext to the tests. Playwright does not check types, and runs tests even with some type errors. Its docs say to run the TypeScript compiler alongside Source 8সোর্স 8. In CI, runnpx tsc -p tsconfig.json --noEmitbefore the tests Source 8সোর্স 8. - Check while you type. Add
-wto keep checking every time you save Source 8সোর্স 8. - Describe the API answers. An interface describes the shape of an object Source 1সোর্স 1: write one for each response body. A wrong field name then fails the check, instead of giving
undefinedSource 2সোর্স 2. - Close the lists. A union of exact values, like the allowed roles, rejects anything else Source 3সোর্স 3.
- Mark what can be missing. Use
?for fields that may be absent Source 3সোর্স 3, and let strict null checks make the code handle them Source 3সোর্স 3. - Reuse helpers. A generic helper works with many types Source 9সোর্স 9.
বাংলা ব্যাখ্যা
- টেস্টের পাশে
tscচালান। Playwright type check করে না, আর ছোটখাটো compile error থাকলেও টেস্ট চালায়। এর docs পাশাপাশি TypeScript compiler চালাতে বলে Source 8সোর্স 8। CI-তে সেটা হলোnpx playwright test-এর আগেnpx tsc -p tsconfig.json --noEmitSource 8সোর্স 8। - লেখার সময়ই check। Local-এ
npx tsc -p tsconfig.json --noEmit -wপ্রতিবার সেভ করার সাথে সাথে check করতে থাকে Source 8সোর্স 8। - API response-এর type দিন। Interface declaration একটা object-এর আকার বর্ণনা করে Source 1সোর্স 1: টেস্ট যে response body পড়ে, তার প্রতিটার জন্য একটা লিখুন। নেই এমন field পড়লে JavaScript-এ
undefinedআসে, কিন্তু TypeScript-এ error হয় Source 2সোর্স 2, তাই field-এর নামে ভুল থাকলে check fail করে। - তালিকা বন্ধ রাখুন। Allowed role বা status-এর মতো literal type-এর union তালিকার বাইরের যেকোনো value বাতিল করে Source 3সোর্স 3।
- যা না থাকতে পারে, তা চিহ্নিত করুন। Optional property দেখায় কোন field না-ও থাকতে পারে Source 3সোর্স 3, আর
strictNullChecksকোডকে সেগুলো চেক করতে বাধ্য করে Source 3সোর্স 3। - Helper আবার ব্যবহার করুন। Generic component একটা type-এর বদলে নানা type নিয়ে কাজ করতে পারে Source 9সোর্স 9।
Common mistakes
- Trusting a green run. Playwright runs tests even when there are non-critical type errors Source 8সোর্স 8, and Node.js does no type checking Source 7সোর্স 7. Run
tscas well, as the Playwright docs recommend Source 8সোর্স 8. anyto silence an error. A value of typeanyis not type-checked Source 3সোর্স 3. Fix the type instead.strictturned off. WithoutstrictNullChecks,nullandundefinedare assignable to any other type, and forgetting to handle them is the cause of countless bugs Source 2সোর্স 2. Step 4 of Try it shows one: aTypeErrorat run time.- Expecting types to check data at run time. Type annotations never change the runtime behaviour Source 2সোর্স 2. Check the shape of an API response with an assertion in the test.
readonlyas protection. Areadonlyproperty is checked only during type-checking; nothing changes at run time Source 4সোর্স 4.
সহজ English
- Trusting a green run. Playwright runs tests even with some type errors Source 8সোর্স 8, and Node.js checks no types Source 7সোর্স 7. Run
tsctoo, as the Playwright docs say Source 8সোর্স 8. - Using
anyto hide an error.anyswitches the check off for that value Source 3সোর্স 3. Fix the type instead. - Turning
strictoff. Thennullandundefinedcan go anywhere, and forgetting them causes countless bugs Source 2সোর্স 2. Step 4 of Try it shows one. - Thinking types check real data. Type annotations never change what runs Source 2সোর্স 2. Check the API answer with an assertion.
- Trusting
readonlyat run time. It is checked only by the checker Source 4সোর্স 4.
বাংলা ব্যাখ্যা
- সবুজ run-এ ভরসা করা। ছোটখাটো type error থাকলেও Playwright টেস্ট চালায় Source 8সোর্স 8, আর Node.js কোনো type check করে না Source 7সোর্স 7। Playwright-এর docs যেমন বলে,
tsc-ও চালান Source 8সোর্স 8। - Error চাপা দিতে
any।anytype-এর value type-check হয় না Source 3সোর্স 3। তার বদলে type ঠিক করুন। strictবন্ধ রাখা।strictNullChecksছাড়াnullআরundefinedযেকোনো type-এ বসানো যায়, আর এগুলো সামলাতে ভুলে যাওয়া অসংখ্য bug-এর কারণ Source 2সোর্স 2। Try it-এর ধাপ 4-এ এমন একটা দেখা গেছে: চলার সময়TypeError।- ভাবা যে type চলার সময় ডেটা চেক করে। Type annotation কখনো চলার সময়ের আচরণ বদলায় না Source 2সোর্স 2। API response-এর shape টেস্টে assertion দিয়ে চেক করুন।
readonly-কে সুরক্ষা ভাবা।readonlyশুধু type-checking-এর সময় চেক হয়; চলার সময় কিছু বদলায় না Source 4সোর্স 4।
What a tester can check
Tutorial advice
This list is the tutorial's own advice, not a fact from a source.
- A type-check step. Does CI run
tsc --noEmit, and does a type error fail the build? strict. Isstricton in thetsconfig.jsonof the tests?any. How manyanytypes are in the test code, and does each one have a reason?- Response types. Do the API tests describe their response bodies with interfaces or types?
- Closed lists. Are statuses and roles unions of literal types, not plain strings?
- Runtime checks. Does each test still assert on the real data, not only on the types?
সহজ English
Tutorial advice
This list is the tutorial's own advice, not a fact from a source.
- Type check. Does CI run
tsc --noEmit, and does an error stop the build? strict. Isstrictturned on for the tests?any. How manyanytypes are there, and does each have a reason?- Response types. Do API tests describe the response bodies?
- Closed lists. Are statuses and roles lists of exact values?
- Real checks. Do the tests still check the real data?
বাংলা ব্যাখ্যা
Tutorial advice
এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, কোনো source থেকে নেওয়া তথ্য নয়।
- Type-check-এর ধাপ। CI কি
tsc --noEmitচালায়, আর type error হলে কি build fail হয়? strict। টেস্টেরtsconfig.json-এ কিstrictচালু?any। টেস্ট কোডে কতগুলোanyআছে, আর প্রতিটার কি কোনো কারণ আছে?- Response type। API টেস্টগুলো কি interface বা type দিয়ে response body বর্ণনা করে?
- বন্ধ তালিকা। Status আর role কি literal type-এর union, সাধারণ string নয়?
- চলার সময়ের চেক। প্রতিটা টেস্ট কি শুধু type নয়, আসল ডেটার ওপরও assert করে?
Key words
| Term | Meaning |
|---|---|
| TypeScript | JavaScript with a type system on top. |
tsc | The TypeScript compiler, the tool that checks the types. |
| Type annotation | A type such as person: string on a parameter, which describes what values the function can be called with; it does not change how the code runs. |
| Type alias | A name for any type: type Role = .... |
| Interface | A name for an object type. |
| Union type | A value that may be any one of two or more types. |
| Literal type | One exact string or number used as a type. |
| Optional property | A property marked with ? that may be missing. |
any | A type that is not checked. |
strict | The flag that turns on the strict family of checks, including strictNullChecks. |
| Narrowing | TypeScript working out a more exact type after a check such as typeof. |
| Type stripping | Node.js removing the types and running the code, with no type check. |