Fix #655 - Provide in-package type definitions

This commit is contained in:
Faisal Salman
2023-10-02 14:35:29 +07:00
parent f6fbf170e3
commit 5a0d9cc3d0
4 changed files with 155 additions and 1 deletions

42
test/dts-test.ts Normal file
View File

@@ -0,0 +1,42 @@
import { expectType } from 'tsd';
import { UAParser, IResult, IBrowser, ICPU, IEngine, IDevice, IOS } from "../src/main/ua-parser";
const uastring = 'Mozilla/5.0 (X11; MyCustomOS; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0';
const extensions = {
os : [
[/(mycustomos)/], [UAParser.OS.NAME, [UAParser.OS.VERSION, '10']]
]
};
const headers = {
'sec-ch-ua-mobile' : '?1'
};
expectType<IResult>(UAParser());
expectType<IResult>(UAParser(uastring));
expectType<IResult>(UAParser(uastring, extensions));
expectType<IResult>(UAParser(uastring, headers));
expectType<IResult>(UAParser(extensions, headers));
expectType<IResult>(UAParser(extensions));
expectType<IResult>(UAParser(headers));
expectType<UAParser>(new UAParser());
const parser = new UAParser(uastring);
const browser = parser.getBrowser();
expectType<IBrowser>(browser);
expectType<string | undefined>(browser.name);
expectType<string | undefined>(browser.version);
expectType<string | undefined>(browser.major);
expectType<boolean>(browser.is(''));
expectType<string>(browser.toString());
expectType<IBrowser | PromiseLike<IBrowser>>(browser.withClientHints());
expectType<IBrowser>((<IBrowser>browser.withClientHints()).withFeatureCheck());
expectType<boolean>((<IBrowser>browser.withClientHints()).withFeatureCheck().is(''));
expectType<ICPU>(parser.getCPU());
expectType<IDevice>(parser.getDevice());
expectType<IEngine>(parser.getEngine());
expectType<IOS>(parser.getOS());
expectType<IResult>(parser.getResult());
expectType<string>(parser.getUA());
expectType<UAParser>(parser.setUA(uastring));