Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
strict typescript
Browse files Browse the repository at this point in the history
and remove old unused imports
  • Loading branch information
Simon-Laux committed Oct 1, 2021
1 parent 1860832 commit 673c276
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
## Changed
- rename `DeltaChat` to `AccountManager`
- rename `DeltaChat.accounts()` to `AccountManager.getAllAccountIds()`
- enable strict typescript

## Fixed
- Fix documentation comment of `AccountManager`
Expand Down
9 changes: 9 additions & 0 deletions lib/binding.ts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/chat.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/chatlist.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion lib/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
18 changes: 8 additions & 10 deletions lib/context.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -164,7 +162,7 @@ export class Context {
this.dcn_context,
Number(messageId),
setupCode,
(result) => resolve(result === 1)
(result: number) => resolve(result === 1)
)
})
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions lib/deltachat.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/message.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"module": "commonjs",
"target": "es5",
"esModuleInterop": true,
"declaration": true
"declaration": true,
"strictNullChecks": true,
"strict": true
},
"typedocOptions": {
"mode": "file",
Expand Down

0 comments on commit 673c276

Please sign in to comment.