Skip to content

Commit

Permalink
fix strict null types & object type (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Jul 13, 2024
1 parent e00091e commit b4016ae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"forceConsistentCasingInFileNames": true,
"types": ["node"]
Expand Down
54 changes: 30 additions & 24 deletions typings/index-template.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -96,14 +98,18 @@ export interface LoginPacket {
isFlat?: boolean
}

type RequireOnly<T, K extends keyof T> = Partial<T> & Required<Pick<T, K>>

type IndexedBlock = RequireOnly<Block, 'minStateId' | 'maxStateId' | 'defaultState'>

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<string, string | number> },
pe: { name: string, states: Record<string, string | number> }
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions typings/test-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b4016ae

Please sign in to comment.