Global type definitions for Tsonic dotnet mode (noLib: true)
npm install @tsonic/dotnet-globalsGlobal type definitions for Tsonic in dotnet mode.
This package provides the minimal global/intrinsic types required by TypeScript when noLib: true is set, while preserving .NET semantics.
Key principle: In dotnet mode, JavaScript array/string methods are NOT available. Use BCL and LINQ instead.
Install this package in your Tsonic project:
``bash`
npm install @tsonic/dotnet-globals
Add to your tsconfig.json:
`json`
{
"compilerOptions": {
"noLib": true,
"types": ["@tsonic/dotnet-globals"]
}
}
Set your tsonic.json mode (or omit for default):
`json`
{
"mode": "dotnet"
}
- Array - WITHOUT JS methods like .length, .map, .filterString
- - WITHOUT JS methods like .slice, .includesNumber
- , Boolean, Object, Function - minimal definitionsPromise
- - for async/await supportfor-of
- Iterator types - for loopsPartial
- Utility types - , Readonly, Pick, etc.
- No .length on arrays - use list.Count from BCL.map()
- No , .filter(), etc. - use LINQ methods from System.LinqString
- No string instance methods - use BCL static methodsFile
- No DOM types - no , Document, HTMLElement, etc.Buffer
- No Node.js types - no , process, etc.
`typescript
import { Console } from "System";
import { List } from "System.Collections.Generic";
// Array literals are List
const numbers = [1, 2, 3, 4, 5];
// ❌ ERROR: Property 'length' does not exist on type 'number[]'
// console.log(numbers.length);
// ✅ CORRECT: Use BCL List
const list = new List
Console.WriteLine(list.Count); // 5
// ❌ ERROR: Property 'map' does not exist on type 'number[]'
// const doubled = numbers.map(x => x * 2);
// ✅ CORRECT: Use LINQ
import { Enumerable } from "System.Linq";
const doubled = Enumerable.Select(numbers, x => x * 2);
`
To switch to JavaScript semantics (with .length, .map(), etc.), use @tsonic/js-globals instead:
1. Uninstall this package: npm uninstall @tsonic/dotnet-globalsnpm install @tsonic/js-globals
2. Install JS globals: tsconfig.json
3. Update : "types": ["@tsonic/js-globals"]tsonic.json
4. Update : "mode": "js"`
MIT