js-codepage icon indicating copy to clipboard operation
js-codepage copied to clipboard

TS bugfix, export top-level indexer

Open karikera opened this issue 5 years ago • 5 comments

TS bugfix, export top-level indexer

export default cptable does not equal with module.exports = cptable, it will export like module.exports["default"] = cptable

karikera avatar Mar 05 '20 09:03 karikera

Coverage Status

Coverage remained the same at 97.494% when pulling 3d6bf311b8e93561f220fc30d09b75b7888f967d on karikera:patch-1 into 62fd61e2b7122819fb9a49dc83917d3daee881d9 on SheetJS:master.

coveralls avatar Mar 05 '20 09:03 coveralls

One of the comments in the original code was:

/* note: TS cannot export top-level indexer, hence default workaround */

I assume this was in an older version of typescript. Can you verify the new export works in older versions of TS? I think we need to test back to 2.2

SheetJSDev avatar Mar 05 '20 17:03 SheetJSDev

@SheetJSDev image

I compiled index.d.ts without error in [email protected]

karikera avatar Mar 05 '20 18:03 karikera

So I had to add "strictFunctionTypes": true to types/tsconfig.json. To test the type definitions, make tslint and it shows errors like

/tmp/js-codepage/types/codepage-test.ts:1:8
ERROR: 1:8    expect                           TypeScript@next compile error: 
Module '"/tmp/js-codepage/types/index"' has no default export.

The offending test code was:

import cptable from 'codepage';

This was fixed in the type definition using

export default cptable;

Is there a reason to prefer export = cptable over export default?

SheetJSDev avatar Mar 05 '20 18:03 SheetJSDev

@SheetJSDev export default is not compiled to module.exports = cptable export default cptable is module.exports['default'] = cptable

this module has errors on TS

image

karikera avatar Mar 05 '20 18:03 karikera