Skip to content

Commit

Permalink
feat: add support for old typescript < 5.6 to fix the error TS2526
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Mar 2, 2025
1 parent 6cd2f55 commit 4994864
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 3.17.0 (2025-03-02)

- feat: add support for old `typescript` < `5.6` to fix the error TS2526:
```
A 'this' type is available only in a non-static member of a class or interface.
```
NOTE: if you use already `typescript` >= `5.6`, you can skip this version.

## 3.16.0 (2025-02-21)

- chore: after testing bump version to release version 3.16.0
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ansis",
"version": "3.16.0",
"version": "3.17.0",
"description": "A small and fast library for applying ANSI colors in terminal or browser console",
"keywords": [
"ansi",
Expand Down Expand Up @@ -85,7 +85,7 @@
"swc": "^1.0.11",
"terser": "^5.39.0",
"tsup": "^8.3.6",
"typescript": "^5.7.3",
"typescript": "5.4.5",
"vitest": "^3.0.5"
},
"overrides": {
Expand Down
2 changes: 1 addition & 1 deletion package.npm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"ansis",
"version":"3.16.0",
"version":"3.17.0",
"description":"ANSI color lib",
"keywords":["ansi","color","cli"],
"license":"ISC",
Expand Down
2 changes: 1 addition & 1 deletion src/color-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let detectColorSpace = (env, isTTY, isWin) => {
// note: the order of checks is important
// many terminals that support truecolor have TERM as `xterm-256colors` and `COLORTERM=truecolor`
// or do not set COLORTERM to `truecolor`
// therefore they can be detected by specific EVN variables
// therefore they can be detected by specific ENV variables

// 1) Detect color support in COLORTERM
// Common COLORTERM Values: `truecolor` or `24bit`, `ansi256`, `ansi`
Expand Down
8 changes: 6 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ type DP = {
};

// Static properties and methods (StaticMethods)
type SP = {
// Compatibility note:
// - typescript <= 5.5: The `this` can be used within a method of an `interface`.
// - typescript >= 5.6: The `this` can be used within a method of a `type`.
interface SP {
(value: unknown): string;

(strings: TemplateStringsArray, ...values: any[]): string;
Expand Down Expand Up @@ -167,10 +170,11 @@ type SP = {

/** The ANSI escape sequences for ending the current style. */
close: string;
};
}

// Combine dynamic and static properties
type Ansis = SP & DP;

// Short alias for Ansis
type A = Ansis;

Expand Down
4 changes: 4 additions & 0 deletions test/ts-compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ describe('imports from package with type module', () => {
test('module Node16', () => executeTSFile('ts/module-import-node16', 'tsc'));
test('module ESNext, tsup', () => executeTSFile('ts/module-import-esnext', 'tsup_esm'));
test('module Node16, tsup', () => executeTSFile('ts/module-import-node16', 'tsup_esm_node16'));
});

describe('typescript = 5.4', () => {
test('method extend Node16', () => executeTSFile('ts/extend-colors-ts5.4', 'tsc'));
});
1 change: 1 addition & 0 deletions test/ts/extend-colors-ts5.4/expected/index.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
8 changes: 8 additions & 0 deletions test/ts/extend-colors-ts5.4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"build": "rimraf --glob dist/*.* && tsc && node dist/index.js --color=true > dist/index.out"
},
"devDependencies": {
"typescript": "=5.4.5"
}
}
11 changes: 11 additions & 0 deletions test/ts/extend-colors-ts5.4/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ansis from 'ansis';

const myTheme = {
pink: '#FF75D1',
orange: '#FFAB40',
apple: '#4FA83D',
};

ansis.extend(myTheme);

console.log(ansis.pink.underline('Hello'));
10 changes: 10 additions & 0 deletions test/ts/extend-colors-ts5.4/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion test/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const executeTSFile = (testPath, compiler = 'tsc', script = null) => {

expect(received).toEqual(expected);
});
// debugging inner errors
//debugging inner errors
// .catch((error) => {
// let message;
// //console.log('>> err: ', error);
Expand Down

0 comments on commit 4994864

Please sign in to comment.