Skip to content

Commit

Permalink
fix: Fix TypeScript declaration inheritance (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapsssito committed Dec 24, 2020
1 parent 98c7d45 commit 3e5b4f7
Show file tree
Hide file tree
Showing 11 changed files with 1,658 additions and 803 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
examples/
ios/
android/
android/
lib/types/
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"no-var": "error",
"prefer-template": 2,
"require-atomic-updates": "off",
"prettier/prettier": ["error"]
"prettier/prettier": ["error", {"endOfLine": "auto"}
]
},
"globals": {
"__DEV__": true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ node_modules

# OS X
.DS_Store
/.vscode
6 changes: 3 additions & 3 deletions __tests__/normalizeBindOptions.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import normalizeBindOptions from '../src/normalizeBindOptions'

describe('normalizeBindOptions', function() {
it('should support all combinations of arguments for [port], [address], [callback]', function() {
describe('normalizeBindOptions', function () {
it('should support all combinations of arguments for [port], [address], [callback]', function () {
const args = [
{ name: 'port', value: 1234 },
{ name: 'address', value: '1.2.3.4' },
Expand All @@ -22,7 +22,7 @@ describe('normalizeBindOptions', function() {
}
})

it('should support all combinations of arguments for [options], [callback]', function() {
it('should support all combinations of arguments for [options], [callback]', function () {
const callback = () => {}
const inOut = [
[[{ port: 123 }, callback], { port: 123, callback }],
Expand Down
7 changes: 7 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"typeRoots": ["../node_modules/@types", "../lib/types"],
},
"include": ["./**/*"]
}
2 changes: 1 addition & 1 deletion declaration.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"emitDeclarationOnly": true,
"outDir": "./lib/types"
},
"exclude": ["lib", "__tests__", "__mocks__"]
"include": ["src"]
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"ci": "yarn install --frozen-lockfile && yarn lint && yarn declaration:build && yarn checkjs && yarn test",
"lint": "eslint .",
"checkjs": "tsc",
"checkjs": "tsc && tsc -p ./__tests__/tsconfig.json",
"test": "jest ./__tests__",
"declaration:build": "tsc -p ./declaration.tsconfig.json",
"prepublishOnly": "yarn declaration:build && yarn checkjs"
Expand Down Expand Up @@ -57,19 +57,19 @@
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.7",
"@semantic-release/npm": "^7.0.5",
"@types/base64-js": "^1.3.0",
"@types/jest": "^26.0.10",
"@types/events": "^3.0.0",
"@types/jest": "^26.0.19",
"@types/react-native": "^0.63.10",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.9.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-jest": "^23.4.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"eslint": "^7.16.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.3.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"react-native": "^0.61.5",
"semantic-release": "^17.1.1",
"typescript": "^4.0.2"
"typescript": "^4.1.3"
}
}
7 changes: 5 additions & 2 deletions src/UdpSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const STATE = {
BOUND: 2,
}

/**
* @typedef {"ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"} BufferEncoding
*/
export default class UdpSocket extends EventEmitter {
/**
* @param {{ type: string; reusePort?: boolean; debug?: boolean; }} options
Expand Down Expand Up @@ -92,7 +95,7 @@ export default class UdpSocket extends EventEmitter {
* @param {any} err
* @param {{ address: any; port: any; }} addr
*/
function(err, addr) {
function (err, addr) {
err = normalizeError(err)
if (err) {
// questionable: may want to self-destruct and
Expand Down Expand Up @@ -260,7 +263,7 @@ export default class UdpSocket extends EventEmitter {
} else if (Buffer.isBuffer(msg)) {
return msg
} else if (msg instanceof Uint8Array || Array.isArray(msg)) {
return Buffer.from(msg)
return Buffer.from(/** @type {any[]} */ (msg))
} else {
throw new TypeError(`Invalid type for msg, found ${typeof msg}`)
}
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import UdpSocket from './UdpSocket'

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

export default UdpSockets

// @ts-ignore
module.exports = UdpSockets
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"typeRoots": ["@types/events"]
},
"include": ["src", "lib", "__tests__", "__mocks__"],
"include": ["src"]
}
Loading

0 comments on commit 3e5b4f7

Please sign in to comment.