Skip to content

Commit 3e5b4f7

Browse files
authored
fix: Fix TypeScript declaration inheritance (#153)
1 parent 98c7d45 commit 3e5b4f7

11 files changed

+1658
-803
lines changed

.eslintignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
examples/
22
ios/
3-
android/
3+
android/
4+
lib/types/

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"no-var": "error",
2424
"prefer-template": 2,
2525
"require-atomic-updates": "off",
26-
"prettier/prettier": ["error"]
26+
"prettier/prettier": ["error", {"endOfLine": "auto"}
27+
]
2728
},
2829
"globals": {
2930
"__DEV__": true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ node_modules
3737

3838
# OS X
3939
.DS_Store
40+
/.vscode

__tests__/normalizeBindOptions.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import normalizeBindOptions from '../src/normalizeBindOptions'
22

3-
describe('normalizeBindOptions', function() {
4-
it('should support all combinations of arguments for [port], [address], [callback]', function() {
3+
describe('normalizeBindOptions', function () {
4+
it('should support all combinations of arguments for [port], [address], [callback]', function () {
55
const args = [
66
{ name: 'port', value: 1234 },
77
{ name: 'address', value: '1.2.3.4' },
@@ -22,7 +22,7 @@ describe('normalizeBindOptions', function() {
2222
}
2323
})
2424

25-
it('should support all combinations of arguments for [options], [callback]', function() {
25+
it('should support all combinations of arguments for [options], [callback]', function () {
2626
const callback = () => {}
2727
const inOut = [
2828
[[{ port: 123 }, callback], { port: 123, callback }],

__tests__/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig",
3+
"compilerOptions": {
4+
"typeRoots": ["../node_modules/@types", "../lib/types"],
5+
},
6+
"include": ["./**/*"]
7+
}

declaration.tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"emitDeclarationOnly": true,
77
"outDir": "./lib/types"
88
},
9-
"exclude": ["lib", "__tests__", "__mocks__"]
9+
"include": ["src"]
1010
}

package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"ci": "yarn install --frozen-lockfile && yarn lint && yarn declaration:build && yarn checkjs && yarn test",
1010
"lint": "eslint .",
11-
"checkjs": "tsc",
11+
"checkjs": "tsc && tsc -p ./__tests__/tsconfig.json",
1212
"test": "jest ./__tests__",
1313
"declaration:build": "tsc -p ./declaration.tsconfig.json",
1414
"prepublishOnly": "yarn declaration:build && yarn checkjs"
@@ -57,19 +57,19 @@
5757
"@semantic-release/git": "^9.0.0",
5858
"@semantic-release/github": "^7.0.7",
5959
"@semantic-release/npm": "^7.0.5",
60-
"@types/base64-js": "^1.3.0",
61-
"@types/jest": "^26.0.10",
60+
"@types/events": "^3.0.0",
61+
"@types/jest": "^26.0.19",
6262
"@types/react-native": "^0.63.10",
6363
"babel-eslint": "^10.0.3",
6464
"babel-jest": "^24.9.0",
65-
"eslint": "^6.8.0",
66-
"eslint-config-prettier": "^6.9.0",
67-
"eslint-plugin-jest": "^23.4.0",
68-
"eslint-plugin-prettier": "^3.1.2",
69-
"jest": "^24.9.0",
70-
"prettier": "^1.19.1",
65+
"eslint": "^7.16.0",
66+
"eslint-config-prettier": "^7.1.0",
67+
"eslint-plugin-jest": "^24.1.3",
68+
"eslint-plugin-prettier": "^3.3.0",
69+
"jest": "^26.6.3",
70+
"prettier": "^2.2.1",
7171
"react-native": "^0.61.5",
7272
"semantic-release": "^17.1.1",
73-
"typescript": "^4.0.2"
73+
"typescript": "^4.1.3"
7474
}
7575
}

src/UdpSocket.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const STATE = {
1010
BOUND: 2,
1111
}
1212

13+
/**
14+
* @typedef {"ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"} BufferEncoding
15+
*/
1316
export default class UdpSocket extends EventEmitter {
1417
/**
1518
* @param {{ type: string; reusePort?: boolean; debug?: boolean; }} options
@@ -92,7 +95,7 @@ export default class UdpSocket extends EventEmitter {
9295
* @param {any} err
9396
* @param {{ address: any; port: any; }} addr
9497
*/
95-
function(err, addr) {
98+
function (err, addr) {
9699
err = normalizeError(err)
97100
if (err) {
98101
// questionable: may want to self-destruct and
@@ -260,7 +263,7 @@ export default class UdpSocket extends EventEmitter {
260263
} else if (Buffer.isBuffer(msg)) {
261264
return msg
262265
} else if (msg instanceof Uint8Array || Array.isArray(msg)) {
263-
return Buffer.from(msg)
266+
return Buffer.from(/** @type {any[]} */ (msg))
264267
} else {
265268
throw new TypeError(`Invalid type for msg, found ${typeof msg}`)
266269
}

src/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import UdpSocket from './UdpSocket'
22

3+
/**
4+
* @typedef {import('buffer').Buffer} Buffer
5+
*/
36
class UdpSockets {
47
/**
58
* Creates a `UdpSockets.Socket` object. Once the socket is created, calling
@@ -24,4 +27,5 @@ class UdpSockets {
2427

2528
export default UdpSockets
2629

30+
// @ts-ignore
2731
module.exports = UdpSockets

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"noEmit": true,
66
"strict": true,
77
"skipLibCheck": true,
8+
"typeRoots": ["@types/events"]
89
},
9-
"include": ["src", "lib", "__tests__", "__mocks__"],
10+
"include": ["src"]
1011
}

0 commit comments

Comments
 (0)