need updating definition for Typescript #711

Closed
opened 2017-06-29 09:13:54 +00:00 by duckywang1 · 1 comment
duckywang1 commented 2017-06-29 09:13:54 +00:00 (Migrated from github.com)

I tried to write a demo with typescript and webpack by learning the code at http://sheetjs.com/demos/writexlsx.html.

I wrote the code like this:

import * as XLSX from 'xlsx';  

// did not change anything   
function sheet_from_array_of_arrays(data, opts) {
	var ws = {};
	var range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }};
	for(var R = 0; R != data.length; ++R) {
		for(var C = 0; C != data[R].length; ++C) {
			if(range.s.r > R) range.s.r = R;
			if(range.s.c > C) range.s.c = C;
			if(range.e.r < R) range.e.r = R;
			if(range.e.c < C) range.e.c = C;
			var cell = {v: data[R][C] };
			if(cell.v == null) continue;
			var cell_ref = XLSX.utils.encode_cell({c:C,r:R});
			
			if(typeof cell.v === 'number') cell.t = 'n';
			else if(typeof cell.v === 'boolean') cell.t = 'b';
			else if(cell.v instanceof Date) {
				cell.t = 'n'; cell.z = XLSX.SSF._table[14];
				cell.v = datenum(cell.v);
			}
			else cell.t = 's';
			
			ws[cell_ref] = cell;
		}
	}
	if(range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
	return ws;
}

The code runs well and I can download xlsx as well.

Here comes the question:
But awesome-typescript-loader told me TS2339: Property 'SSF' does not exist on type 'typeof "./node_modules/xlsx/types/index"'

Thanks for sheetjs and this great node module.

I tried to write a demo with typescript and webpack by learning the code at `http://sheetjs.com/demos/writexlsx.html`. I wrote the code like this: ``` import * as XLSX from 'xlsx'; // did not change anything function sheet_from_array_of_arrays(data, opts) { var ws = {}; var range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }}; for(var R = 0; R != data.length; ++R) { for(var C = 0; C != data[R].length; ++C) { if(range.s.r > R) range.s.r = R; if(range.s.c > C) range.s.c = C; if(range.e.r < R) range.e.r = R; if(range.e.c < C) range.e.c = C; var cell = {v: data[R][C] }; if(cell.v == null) continue; var cell_ref = XLSX.utils.encode_cell({c:C,r:R}); if(typeof cell.v === 'number') cell.t = 'n'; else if(typeof cell.v === 'boolean') cell.t = 'b'; else if(cell.v instanceof Date) { cell.t = 'n'; cell.z = XLSX.SSF._table[14]; cell.v = datenum(cell.v); } else cell.t = 's'; ws[cell_ref] = cell; } } if(range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); return ws; } ``` The code runs well and I can download xlsx as well. Here comes the question: But `awesome-typescript-loader` told me `TS2339: Property 'SSF' does not exist on type 'typeof "./node_modules/xlsx/types/index"'` Thanks for sheetjs and this great node module.
reviewher commented 2017-06-29 17:30:45 +00:00 (Migrated from github.com)

You are correct, the definition for SSF is missing. We'll accept a pull request that just declares SSF as any. The definition file is types/index.d.ts and a line like

export const SSF:any;

should appease typescript.

Note: that function was brought into the library as XLSX.utils.aoa_to_sheet: https://github.com/SheetJS/js-xlsx/#array-of-arrays-input and you should be using it instead of the external function.

You are correct, the definition for SSF is missing. We'll accept a pull request that just declares SSF as any. The definition file is [`types/index.d.ts`](https://github.com/SheetJS/js-xlsx/blob/master/types/index.d.ts) and a line like ```typescript export const SSF:any; ``` should appease typescript. Note: that function was brought into the library as `XLSX.utils.aoa_to_sheet`: https://github.com/SheetJS/js-xlsx/#array-of-arrays-input and you should be using it instead of the external function.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#711
No description provided.