diff --git a/CHANGELOG.md b/CHANGELOG.md index dc398768..8084c2a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ## Changed - rename `DeltaChat` to `AccountManager` - rename `DeltaChat.accounts()` to `AccountManager.getAllAccountIds()` +- enable strict typescript ## Fixed - Fix documentation comment of `AccountManager` diff --git a/lib/binding.ts b/lib/binding.ts new file mode 100644 index 00000000..72875aa4 --- /dev/null +++ b/lib/binding.ts @@ -0,0 +1,9 @@ +import { join } from 'path' + +/** + * bindings are not typed yet. + * if the availible function names are required they can be found inside of `../src/module.c` + */ +export const bindings: any = require('node-gyp-build')(join(__dirname, '../')) + +export default bindings diff --git a/lib/chat.ts b/lib/chat.ts index 232b9788..e36de4a9 100644 --- a/lib/chat.ts +++ b/lib/chat.ts @@ -1,6 +1,6 @@ /* eslint-disable camelcase */ -import binding from '../binding' +import binding from './binding' import rawDebug from 'debug' const debug = rawDebug('deltachat:node:chat') import { C } from './constants' diff --git a/lib/chatlist.ts b/lib/chatlist.ts index 886f4201..92d022fc 100644 --- a/lib/chatlist.ts +++ b/lib/chatlist.ts @@ -1,6 +1,6 @@ /* eslint-disable camelcase */ -const binding = require('../binding') +import binding from './binding' import { Lot } from './lot' import { Chat } from './chat' const debug = require('debug')('deltachat:node:chatlist') diff --git a/lib/contact.ts b/lib/contact.ts index 2dcb6c16..6930e2c6 100644 --- a/lib/contact.ts +++ b/lib/contact.ts @@ -2,7 +2,7 @@ import { integerToHexColor } from './util' /* eslint-disable camelcase */ -const binding = require('../binding') +import binding from './binding' const debug = require('debug')('deltachat:node:contact') interface NativeContact {} diff --git a/lib/context.ts b/lib/context.ts index 0b4fb099..a9a28203 100644 --- a/lib/context.ts +++ b/lib/context.ts @@ -1,14 +1,12 @@ /* eslint-disable camelcase */ -import binding from '../binding' -import { C, EventId2EventName } from './constants' -import { EventEmitter } from 'events' +import binding from './binding' +import { C } from './constants' import { Chat } from './chat' import { ChatList } from './chatlist' import { Contact } from './contact' import { Message } from './message' import { Lot } from './lot' -import { mkdtempSync } from 'fs' import { Locations } from './locations' import pick from 'lodash.pick' import rawDebug from 'debug' @@ -36,7 +34,7 @@ export class Context { unref() { binding.dcn_context_unref(this.dcn_context) - this.inner_dcn_context = null + ;(this.inner_dcn_context as any) = null } acceptChat(chatId: number) { @@ -124,12 +122,12 @@ export class Context { removeListeners() resolve() } - const onFail = (error) => { + const onFail = (error: string) => { removeListeners() reject(new Error(error)) } - const onConfigure = (accountId, data1, data2) => { + const onConfigure = (accountId: number, data1: number, data2: string) => { if (this.account_id !== accountId) { return } @@ -164,7 +162,7 @@ export class Context { this.dcn_context, Number(messageId), setupCode, - (result) => resolve(result === 1) + (result: number) => resolve(result === 1) ) }) } @@ -291,7 +289,7 @@ export class Context { ) } - getChatMessages(chatId: number, flags, marker1before) { + getChatMessages(chatId: number, flags: number, marker1before: number) { debug(`getChatMessages ${chatId} ${flags} ${marker1before}`) return binding.dcn_get_chat_msgs( this.dcn_context, @@ -509,7 +507,7 @@ export class Context { binding.dcn_imex(this.dcn_context, what, param1, param2) } - importExportHasBackup(dir) { + importExportHasBackup(dir: string) { debug(`importExportHasBackup ${dir}`) return binding.dcn_imex_has_backup(this.dcn_context, dir) } diff --git a/lib/deltachat.ts b/lib/deltachat.ts index 79e70de7..7b305b26 100644 --- a/lib/deltachat.ts +++ b/lib/deltachat.ts @@ -1,7 +1,7 @@ /* eslint-disable camelcase */ -import binding from '../binding' -import { C, EventId2EventName } from './constants' +import binding from './binding' +import { EventId2EventName } from './constants' import { EventEmitter } from 'events' import { existsSync } from 'fs' import rawDebug from 'debug' @@ -142,7 +142,7 @@ export class AccountManager extends EventEmitter { static parseGetInfo(info: string) { debug('static _getInfo') - const result = {} + const result: { [key: string]: string } = {} const regex = /^(\w+)=(.*)$/i info diff --git a/lib/message.ts b/lib/message.ts index 43a7d68f..7abf66b6 100644 --- a/lib/message.ts +++ b/lib/message.ts @@ -1,6 +1,6 @@ /* eslint-disable camelcase */ -import binding from '../binding' +import binding from './binding' import { C } from './constants' import { Lot } from './lot' import { Chat } from './chat' diff --git a/package.json b/package.json index a5a83c41..35adf707 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,8 @@ "split2": "^3.1.1" }, "devDependencies": { + "@types/debug": "^4.1.7", + "@types/lodash.pick": "^4.4.6", "@types/node": "^14.17.5", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", diff --git a/tsconfig.json b/tsconfig.json index d8c321e3..68071a02 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,9 @@ "module": "commonjs", "target": "es5", "esModuleInterop": true, - "declaration": true + "declaration": true, + "strictNullChecks": true, + "strict": true }, "typedocOptions": { "mode": "file",