@tsonic/dotnet-globals
v0.2.1
Published
Global type definitions for Tsonic dotnet mode (noLib: true)
Downloads
19
Maintainers
Readme
@tsonic/dotnet-globals
Global type definitions for Tsonic in dotnet mode.
Purpose
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.
Usage
Install this package in your Tsonic project:
npm install @tsonic/dotnet-globalsAdd to your tsconfig.json:
{
"compilerOptions": {
"noLib": true,
"types": ["@tsonic/dotnet-globals"]
}
}Set your tsonic.json mode (or omit for default):
{
"mode": "dotnet"
}What This Provides
Minimal Global Types
Array<T>- WITHOUT JS methods like.length,.map,.filterString- WITHOUT JS methods like.slice,.includesNumber,Boolean,Object,Function- minimal definitionsPromise<T>- for async/await support- Iterator types - for
for-ofloops - Utility types -
Partial,Readonly,Pick, etc.
What's NOT Included
- No
.lengthon arrays - uselist.Countfrom BCL - No
.map(),.filter(), etc. - use LINQ methods fromSystem.Linq - No string instance methods - use BCL
Stringstatic methods - No DOM types - no
File,Document,HTMLElement, etc. - No Node.js types - no
Buffer,process, etc.
Example
import { Console } from "System";
import { List } from "System.Collections.Generic";
// Array literals are List<T> compatible
const numbers = [1, 2, 3, 4, 5];
// ❌ ERROR: Property 'length' does not exist on type 'number[]'
// console.log(numbers.length);
// ✅ CORRECT: Use BCL List<T> methods
const list = new List<number>(numbers);
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);Mode Switching
To switch to JavaScript semantics (with .length, .map(), etc.), use @tsonic/js-globals instead:
- Uninstall this package:
npm uninstall @tsonic/dotnet-globals - Install JS globals:
npm install @tsonic/js-globals - Update
tsconfig.json:"types": ["@tsonic/js-globals"] - Update
tsonic.json:"mode": "js"
License
MIT
