From cf91be6b853c9e07df70953ef1ddd8570dcc25e3 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Sat, 28 Sep 2024 19:14:27 +0100 Subject: [PATCH] Fix forSchema argument type (#476) Also introduce a CI check to test the type definitions. --- .github/workflows/ci.yml | 2 ++ package-lock.json | 56 +++++++++++++++++++++++++++++++++++++++- package.json | 7 +++-- types/index.d.ts | 5 ++-- types/test/461.ts | 15 +++++++++++ 5 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 types/test/461.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f6bb514..20b00e09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,3 +32,5 @@ jobs: run: npm i - name: Test run: npm t + - name: Check types + run: npm run check-types diff --git a/package-lock.json b/package-lock.json index e795dc5a..5075c77c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,13 @@ "version": "6.0.0-rc.1", "license": "MIT", "devDependencies": { + "@types/node": "^22.5.5", "benchmark": "~2.1.4", "eslint": "^8.30.0", "mocha": "^10.2.0", "nyc": "~15.0.0", - "tmp": "^0.1.0" + "tmp": "^0.1.0", + "typescript": "^5.6.2" }, "engines": { "node": ">=6.0.0" @@ -437,6 +439,16 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "node_modules/@types/node": { + "version": "22.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", + "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.19.2" + } + }, "node_modules/acorn": { "version": "8.8.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", @@ -3022,6 +3034,27 @@ "is-typedarray": "^1.0.0" } }, + "node_modules/typescript": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true, + "license": "MIT" + }, "node_modules/uri-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", @@ -3647,6 +3680,15 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/node": { + "version": "22.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", + "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", + "dev": true, + "requires": { + "undici-types": "~6.19.2" + } + }, "acorn": { "version": "8.8.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", @@ -5591,6 +5633,18 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", + "dev": true + }, + "undici-types": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true + }, "uri-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", diff --git a/package.json b/package.json index 95ea28e0..bcc4a759 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "files": [ "etc/browser", "lib", - "types" + "types/index.d.ts" ], "main": "./lib", "types": "./types", @@ -43,6 +43,7 @@ "node": ">=6.0.0" }, "scripts": { + "check-types": "tsc --strict --noEmit types/test/*.ts", "clean": "rm -rf coverage node_modules", "cover": "nyc mocha -- --ui tdd", "lint": "eslint etc/ lib/ test/ \"etc/scripts/**\"", @@ -50,11 +51,13 @@ "test": "mocha --ui tdd --reporter dot" }, "devDependencies": { + "@types/node": "^22.5.5", "benchmark": "~2.1.4", "eslint": "^8.30.0", "mocha": "^10.2.0", "nyc": "~15.0.0", - "tmp": "^0.1.0" + "tmp": "^0.1.0", + "typescript": "^5.6.2" }, "author": { "name": "Matthieu Monsch", diff --git a/types/index.d.ts b/types/index.d.ts index 33611dd7..76a8019b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -7,12 +7,11 @@ // `any` is appropriate. import * as stream from 'stream'; -import { EventEmitter } from 'events'; //"virtual" namespace (no JS, just types) for Avro Schema declare namespace schema { - export type AvroSchema = DefinedType | DefinedType[] | Type | Type[]; - type DefinedType = PrimitiveType | ComplexType | LogicalType | string; + export type AvroSchema = DefinedType | DefinedType[]; + type DefinedType = PrimitiveType | ComplexType | LogicalType | Type | string; type PrimitiveType = 'null' | 'boolean' | 'int' | 'long' | 'float' | 'double' | 'bytes' | 'string'; type ComplexType = NamedType | RecordType | EnumType | MapType | ArrayType | FixedType; type LogicalType = ComplexType & LogicalTypeExtension; diff --git a/types/test/461.ts b/types/test/461.ts new file mode 100644 index 00000000..c7b426d9 --- /dev/null +++ b/types/test/461.ts @@ -0,0 +1,15 @@ +import * as Avro from '../index' + +const e = Avro.Type.forSchema({ + name: "enum", + type: "enum", + symbols: ["foo", "bar", "baz"], +}); + +const record = Avro.Type.forSchema({ + name: "record", + type: "record", + fields: [ + { name: "enum", type: ["null", e], default: null }, + ], +});