Skip to content

Commit d2b171e

Browse files
Copilotmathiasrw
andauthored
Fix TypeScript type resolution to close #2317 (#2338)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mathiasrw <[email protected]> Co-authored-by: M. Wulff <[email protected]>
1 parent 4aff884 commit d2b171e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"browser": "dist/alasql.min.js",
1111
"exports": {
1212
".": {
13+
"types": "./types/alasql.d.ts",
1314
"node": "./dist/alasql.fs.js",
1415
"browser": "./dist/alasql.min.js",
1516
"default": "./dist/alasql.fs.js"

test/test2317.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
if (typeof exports === 'object') {
2+
var assert = require('assert');
3+
var alasql = require('..');
4+
var fs = require('fs');
5+
var path = require('path');
6+
}
7+
8+
describe('Test 2317 - TypeScript type resolution via exports map', function () {
9+
const test = '2317'; // insert test file number
10+
11+
it('A) package.json should have types in exports map', function () {
12+
// Read package.json
13+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
14+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
15+
16+
// Verify exports field exists
17+
assert.ok(packageJson.exports, 'package.json should have exports field');
18+
19+
// Verify main export has types field
20+
assert.ok(packageJson.exports['.'], 'package.json exports should have "." entry');
21+
assert.ok(packageJson.exports['.'].types, 'package.json exports["."] should have types field');
22+
23+
// Verify types field points to correct file
24+
assert.strictEqual(
25+
packageJson.exports['.'].types,
26+
'./types/alasql.d.ts',
27+
'types field should point to ./types/alasql.d.ts'
28+
);
29+
});
30+
31+
it('B) types file should exist', function () {
32+
// Verify the types file actually exists
33+
const typesFilePath = path.join(__dirname, '..', 'types', 'alasql.d.ts');
34+
assert.ok(fs.existsSync(typesFilePath), 'types/alasql.d.ts should exist');
35+
});
36+
37+
it('C) alasql import should work (runtime verification)', function () {
38+
// Basic runtime check that alasql still works
39+
var res = alasql('SELECT 1 as one');
40+
assert.deepEqual(res, [{one: 1}]);
41+
});
42+
});

0 commit comments

Comments
 (0)