🤖 Merge PR #63825 [add] Add typings for add npm package by @LeoDog896

* [add] Add typings

* Change arrays to readonly

* Use = instead of default for export

* Properly export default function using namespaces
This commit is contained in:
Tristan F
2023-01-06 17:12:15 -05:00
committed by GitHub
parent 4a318f6258
commit dde03dfb4f
4 changed files with 69 additions and 0 deletions

26
types/add/add-tests.ts Normal file
View File

@@ -0,0 +1,26 @@
import add = require("add");
const { dumbSum, fastTwoSum, nextPowerTwo } = add;
// $ExpectType number
add([0.1, 0.2]);
// @ts-expect-error
add(15, 14);
// $ExpectType number
dumbSum([15, 14]);
// @ts-expect-error
dumbSum(20, "a");
// $ExpectType [number, number, null]
fastTwoSum(1 / 3, 1 / 6);
// @ts-expect-error
fastTwoSum(1 / 3);
// $ExpectType number
nextPowerTwo(1534);
// @ts-expect-error
nextPowerTwo(new Symbol());

19
types/add/index.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
// Type definitions for add 2.0
// Project: https://github.com/ben-ng/add
// Definitions by: Tristan F. <https://github.com/LeoDog896>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function accSum(numbers: ReadonlyArray<number>): number;
export = accSum;
declare namespace accSum {
function dumbSum(numbers: ReadonlyArray<number>): number;
function fastTwoSum(a: number, b: number): [number, number, null];
/**
* Finds the immediate power of 2 that is larger than p
* in a fast way
*/
function nextPowerTwo(p: number): number;
}

23
types/add/tsconfig.json Normal file
View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"add-tests.ts"
]
}

1
types/add/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }