Setting Up TypeScript
TypeScript Version
All OP_NET libraries requires TypeScript version 5.9 or higher. Using older versions will produce compilation errors.
Add TypeScript as a development dependency in your package.json file and run npm install to ensure the correct version is available in your project.
json
Add to package.json
"devDependencies": {
"typescript": "^5.9.3"
}bash
Install using npm
npm installVersion 5.9.3 was current at the time of writing. Update to the latest version as needed.
TypeScript Configuration
The library requires ESNext target and strict mode. Create or update your tsconfig.json to includes the following settings.
For Node.js
json
tsconfig.json
{
"compilerOptions": {
// Module system
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
"moduleDetection": "force",
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"isolatedModules": true,
// Strict mode (required)
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
// Output
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"skipLibCheck": true,
// Lib targets
"lib": ["ESNext", "DOM", "DOM.Iterable"]
},
"include": ["src/**/*.ts"]
}Key Configuration Options
| Option | Value | Reason |
|---|---|---|
| target | ESNext | await, using declarations (Symbol.dispose), and other modern syntax. |
| moduleResolution | NodeNext | Proper module resolution for Node.js. |
| strict | true | All public APIs are strictly typed. Disabling strict mode will cause type mismatches. |
| verbatimModuleSyntax | true | The library uses explicit type imports throughout. |
For Browsers
json
tsconfig.json
{
"compilerOptions": {
// Module system
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"isolatedModules": true,
// Strict mode (required)
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
// Output
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"skipLibCheck": true,
// Lib targets
"lib": ["ESNext", "DOM", "DOM.Iterable"]
},
"include": ["src/**/*.ts"]
}Key Configuration Options
| Option | Value | Reason |
|---|---|---|
| target | ESNext | await, using declarations (Symbol.dispose), and other modern syntax. |
| moduleResolution | bundler | Proper module resolution for browser environment. |
| strict | true | All public APIs are strictly typed. Disabling strict mode will cause type mismatches. |
| verbatimModuleSyntax | true | The library uses explicit type imports throughout. |