Skip to content

Commit

Permalink
Fix forSchema argument type (#476)
Browse files Browse the repository at this point in the history
Also introduce a CI check to test the type definitions.
  • Loading branch information
joscha authored Sep 28, 2024
1 parent 14886e8 commit cf91be6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ jobs:
run: npm i
- name: Test
run: npm t
- name: Check types
run: npm run check-types
56 changes: 55 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"files": [
"etc/browser",
"lib",
"types"
"types/index.d.ts"
],
"main": "./lib",
"types": "./types",
Expand All @@ -43,18 +43,21 @@
"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/**\"",
"perf": "node --expose-gc ./etc/scripts/perf etc/schemas/*",
"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",
Expand Down
5 changes: 2 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions types/test/461.ts
Original file line number Diff line number Diff line change
@@ -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 },
],
});

0 comments on commit cf91be6

Please sign in to comment.