From b4016ae7111fbe652cd47dcf227e78d360b2f688 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Sun, 14 Jul 2024 00:05:53 +0300 Subject: [PATCH] fix strict null types & object type (#348) --- tsconfig.json | 2 +- typings/index-template.d.ts | 54 ++++++++++++++++++++----------------- typings/test-typings.ts | 4 +++ 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 539a40c2..827995cc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "forceConsistentCasingInFileNames": true, "types": ["node"] diff --git a/typings/index-template.d.ts b/typings/index-template.d.ts index 43b618d9..66edcb9d 100644 --- a/typings/index-template.d.ts +++ b/typings/index-template.d.ts @@ -1,3 +1,5 @@ +type Object = { [key: string]: any } + export interface Version { // Returns true if the current version is greater than or equal to the `other` version's dataVersion ['>='](other: string): boolean @@ -27,21 +29,21 @@ export interface SupportedVersions { } export interface Schemas { - biomes: object - blocks: object - effects: object - entities: object - instruments: object - items: object - materials: object - protocol: object - protocolVersions: object - recipes: object - version: object - windows: object - foods: object - blockLoot: object - entityLoot: object + biomes: Object + blocks: Object + effects: Object + entities: Object + instruments: Object + items: Object + materials: Object + protocol: Object + protocolVersions: Object + recipes: Object + version: Object + windows: Object + foods: Object + blockLoot: Object + entityLoot: Object } export interface LoginPacket { @@ -65,9 +67,9 @@ export interface LoginPacket { /** * Introduced in Minecraft 1.17 */ - dimensionCodec?: object + dimensionCodec?: Object - dimension: object + dimension: Object /** * Introduced in Minecraft 1.17 @@ -96,14 +98,18 @@ export interface LoginPacket { isFlat?: boolean } +type RequireOnly = Partial & Required> + +type IndexedBlock = RequireOnly + export interface IndexedData { isOlderThan(version: string): boolean isNewerOrEqualTo(version: string): boolean - blocks: { [id: number]: Block } - blocksByName: { [name: string]: Block } - blocksByStateId: { [id: number]: Block } - blocksArray: Block[] + blocks: { [id: number]: IndexedBlock } + blocksByName: { [name: string]: IndexedBlock } + blocksByStateId: { [id: number]: IndexedBlock } + blocksArray: IndexedBlock[] blockMappings: { pc: { name: string, states: Record }, pe: { name: string, states: Record } @@ -151,10 +157,10 @@ export interface IndexedData { /** * Bedrock edition only */ - defaultSkin?: object + defaultSkin?: Object - protocol: object - protocolComments: object + protocol: Object + protocolComments: Object /** * Bedrock edition only */ diff --git a/typings/test-typings.ts b/typings/test-typings.ts index 30e9a4de..61da1d9a 100644 --- a/typings/test-typings.ts +++ b/typings/test-typings.ts @@ -33,6 +33,10 @@ console.log(getMcData('0.30c').version) console.log(getMcData('bedrock_0.14').version) console.log(getMcData('pc_1.9').blocksByName['dirt']) +console.log(getMcData('pc_1.9').blocksByName['dirt'].minStateId.toExponential) + +console.log(getMcData('pc_1.9').protocol.toClient) + console.log(getMcData('bedrock_0.14').blocksByName['podzol']) console.log(getMcData('bedrock_0.14').type)