Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Fixed an issue where optional type information wasn't properly conveyed when inside an Record type.",
"packageName": "@minecraft/markup-generators-plugin",
"email": "alexander.denford@skyboxlabs.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Notes:
## Methods
- [methodThatReturnsOptional](#methodthatreturnsoptional)
- [methodThatTakesOptionals](#methodthattakesoptionals)
- [methodThatTakesRecordOfOptionalVariants](#methodthattakesrecordofoptionalvariants)
- [methodWithDefaultValuesAreOptional](#methodwithdefaultvaluesareoptional)

### **methodThatReturnsOptional**
Expand All @@ -67,6 +68,19 @@ methodThatTakesOptionals(arg1?: boolean, arg2?: string): void
Notes:
- This function can't be called in read-only mode.

### **methodThatTakesRecordOfOptionalVariants**
\`
methodThatTakesRecordOfOptionalVariants(values: Record<string, boolean | number | string | undefined>): void
\`

#### **Parameters**
- **values**: Record<*string*, *boolean* | *number* | *string* | *undefined*>

**Returns** *void*

Notes:
- This function can't be called in read-only mode.

### **methodWithDefaultValuesAreOptional**
\`
methodWithDefaultValuesAreOptional(defaultIs1?: number, defaultIs0?: number, defaultIsFalse?: boolean, defaultIsString?: string, defaultIsArray?: number[]): void
Expand Down Expand Up @@ -205,6 +219,12 @@ export class ClassWithOptionals {
*
*/
methodThatTakesOptionals(arg1?: boolean, arg2?: string): void;
/**
* @remarks
* This function can't be called in read-only mode.
*
*/
methodThatTakesRecordOfOptionalVariants(values: Record<string, boolean | number | string | undefined>): void;
/**
* @remarks
* This function can't be called in read-only mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,71 @@
"base_types": [],
"constants": [],
"functions": [
{
"arguments": [
{
"details": null,
"name": "values",
"type": {
"is_bind_type": true,
"is_errorable": false,
"key_type": {
"is_bind_type": false,
"is_errorable": false,
"name": "string"
},
"name": "map",
"value_type": {
"is_bind_type": true,
"is_errorable": false,
"name": "optional",
"optional_type": {
"is_bind_type": false,
"is_errorable": false,
"name": "variant",
"variant_types": [
{
"is_bind_type": false,
"is_errorable": false,
"name": "boolean"
},
{
"is_bind_type": false,
"is_errorable": false,
"name": "double",
"valid_range": {
"max": 2147483647,
"min": -2147483648
}
},
{
"is_bind_type": false,
"is_errorable": false,
"name": "float",
"valid_range": {
"max": 2147483647,
"min": -2147483648
}
},
{
"is_bind_type": false,
"is_errorable": false,
"name": "string"
}
]
}
}
}
}
],
"is_constructor": false,
"name": "methodThatTakesRecordOfOptionalVariants",
"return_type": {
"is_bind_type": false,
"is_errorable": false,
"name": "void"
}
},
{
"arguments": [],
"is_constructor": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Record of Optional Variants > Generates correct output for record of optional variants > # Of Files Generated 1`] = `4`;

exports[`Record of Optional Variants > Generates correct output for record of optional variants > msdocs/scriptapi/TOC.yml 1`] = `
" - name: exampleMember
items:
- name: exampleMember
href: examplemember/examplemember.md
- name: ClassWithRecordOfOptionalVariantsProperty
href: examplemember/ClassWithRecordOfOptionalVariantsProperty.md
"
`;

exports[`Record of Optional Variants > Generates correct output for record of optional variants > msdocs/scriptapi/examplemember/ClassWithRecordOfOptionalVariantsProperty.md 1`] = `
"---
# DO NOT TOUCH — This file was automatically generated by @minecraft/api-docs-generator, to report problems file an issue at https://github.com/Mojang/minecraft-scripting-libraries
author: jakeshirley
ms.author: jashir
ms.service: minecraft-bedrock-edition
ms.date: 02/10/2025
title: examplemember.ClassWithRecordOfOptionalVariantsProperty Class
description: Contents of the exampleMember.ClassWithRecordOfOptionalVariantsProperty class.
---
# ClassWithRecordOfOptionalVariantsProperty Class

## Properties

### **exampleMember**
\`exampleMember?: Record<string, boolean | number | string | undefined>;\`

Type: Record<*string*, *boolean* | *number* | *string* | *undefined*>

Notes:
- This property can't be used in read-only mode.
"
`;

exports[`Record of Optional Variants > Generates correct output for record of optional variants > msdocs/scriptapi/examplemember/examplemember.md 1`] = `
"---
# DO NOT TOUCH — This file was automatically generated by @minecraft/api-docs-generator, to report problems file an issue at https://github.com/Mojang/minecraft-scripting-libraries
author: jakeshirley
ms.author: jashir
ms.service: minecraft-bedrock-edition
ms.date: 02/10/2025
title: examplemember Module
description: Contents of the exampleMember module
---
# \`exampleMember\` Module

## Manifest Details
\`\`\`json
{
"module_name": "exampleMember",
"version": "1.0.0"
}
\`\`\`
This is version 1.x.x of this module, which is the latest as of version 1.0.0 of Minecraft.

## Available Versions
- \`1.0.0\`

## Classes
- [ClassWithRecordOfOptionalVariantsProperty](ClassWithRecordOfOptionalVariantsProperty.md)
"
`;

exports[`Record of Optional Variants > Generates correct output for record of optional variants > typescript/exampleMember@1.0.0.d.ts 1`] = `
"// Type definitions for Minecraft Bedrock Edition script APIs
// Project: https://docs.microsoft.com/minecraft/creator/
// Definitions by: Jake Shirley <https://github.com/JakeShirley>
// Mike Ammerlaan <https://github.com/mammerla>

/* *****************************************************************************
Copyright (c) Microsoft Corporation.
***************************************************************************** */
/**
* @packageDocumentation
*
* Manifest Details
* \`\`\`json
* {
* "module_name": "exampleMember",
* "version": "1.0.0"
* }
* \`\`\`
*
*/
export class ClassWithRecordOfOptionalVariantsProperty {
private constructor();
/**
* @remarks
* This property can't be used in read-only mode.
*
*/
exampleMember?: Record<string, boolean | number | string | undefined>;
}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// File exists to ensure docs folder exists
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"classes": [
{
"base_types": [],
"constants": [],
"functions": [],
"name": "ClassWithRecordOfOptionalVariantsProperty",
"properties": [
{
"is_read_only": false,
"name": "exampleMember",
"type": {
"is_bind_type": false,
"is_errorable": false,
"name": "optional",
"optional_type": {
"key_type": {
"is_bind_type": false,
"is_errorable": false,
"name": "string"
},
"value_type": {
"is_bind_type": false,
"is_errorable": false,
"name": "optional",
"optional_type": {
"is_bind_type": false,
"is_errorable": false,
"name": "variant",
"variant_types": [
{
"is_bind_type": false,
"is_errorable": false,
"name": "boolean"
},
{
"is_bind_type": false,
"is_errorable": false,
"name": "float",
"valid_range": {
"max": 2147483647,
"min": -2147483648
}
},
{
"is_bind_type": false,
"is_errorable": false,
"name": "string"
}
]
}
},
"is_bind_type": false,
"is_errorable": false,
"name": "map"
}
}
}
],
"type": {
"is_bind_type": true,
"is_errorable": false,
"name": "ClassWithRecordOfOptionalVariantsProperty"
}
}
],
"minecraft_version": "1.0.0",
"name": "exampleMember",
"uuid": "93faf953-0173-44dc-b542-b48f4fea7c4b",
"version": "1.0.0",
"module_type": "script"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { describe, it } from 'vitest';
import { runGeneratorForTest } from '../runGeneratorForTest';

describe('Record of Optional Variants', () => {
it('Generates correct output for record of optional variants', () => {
runGeneratorForTest({
testDir: __dirname,
generators: ['ts', 'msdocs'],
});
});
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#is_void_return}}*void*{{/is_void_return}}{{^is_void_return}}{{#is_data_buffer}}{{#data_buffer_type}}[{{> type}}](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/{{> type}}){{/data_buffer_type}}{{/is_data_buffer}}{{^is_data_buffer}}{{#is_generator}}Generator<{{#generator_type}}{{#yield_type}}{{> type_with_links}}{{/yield_type}}, {{#return_type}}{{> type_with_links}}{{/return_type}}, {{#next_type}}{{> type_with_links}}{{/next_type}}{{/generator_type}}>{{/is_generator}}{{^is_generator}}{{#is_map}}Record<{{#key_type}}{{> type_with_links}}{{/key_type}}, {{#value_type}}{{> type_with_links}}{{/value_type}}>{{/is_map}}{{^is_map}}{{#is_iterator_result}}IteratorResult&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator_result}}{{^is_iterator_result}}{{#is_iterator}}Iterator&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator}}{{^is_iterator}}{{#is_optional_type}}{{#optional_type}}{{> type_with_links}}{{/optional_type}}{{/is_optional_type}}{{^is_optional_type}}{{#is_variant}}{{#variant_types}}{{> type_with_links}}{{^is_last}} | {{/is_last}}{{/variant_types}}{{/is_variant}}{{^is_variant}}{{#is_promise}}Promise&lt;{{#promise_type}}{{> type_with_links}}{{/promise_type}}&gt;{{/is_promise}}{{^is_promise}}{{#is_array}}{{#element_type}}{{#is_optional_type}}{{#optional_type}}({{/optional_type}}{{/is_optional_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_optional_type}}{{#optional_type}} | *undefined*){{/optional_type}}{{/is_optional_type}}{{#is_variant}}){{/is_variant}}[]{{/element_type}}{{/is_array}}{{^is_array}}{{#is_undefined}}*undefined*{{/is_undefined}}{{^is_undefined}}{{#is_closure}}{{#closure_type}}({{#argument_types}}arg{{index}}: {{> type_with_links}}{{^is_last}}, {{/is_last}}{{/argument_types}}) => {{#return_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_variant}}){{/is_variant}}{{/return_type}}{{/closure_type}}{{^closure_type}}() => void{{/closure_type}}{{/is_closure}}{{^is_closure}}{{#argument_valid_values.length}}{{#argument_valid_values}}`'{{argument_valid_value}}'`{{^argument_valid_value_end}}, {{/argument_valid_value_end}}{{/argument_valid_values}}{{/argument_valid_values.length}}{{^argument_valid_values}}{{#is_bind_type}}[{{/is_bind_type}}*{{#from_module.is_external_module}}{{{from_module.name}}}.{{/from_module.is_external_module}}{{{name}}}*{{#is_bind_type}}]({{#from_module.is_external_module}}../../../{{{from_module.folder_path}}}/{{{from_module.filepath_name}}}/{{/from_module.is_external_module}}{{{name}}}.md){{/is_bind_type}}{{/argument_valid_values}}{{/is_closure}}{{/is_undefined}}{{/is_array}}{{/is_promise}}{{/is_variant}}{{/is_optional_type}}{{/is_iterator}}{{/is_iterator_result}}{{/is_map}}{{/is_generator}}{{/is_data_buffer}}{{/is_void_return}}
{{#is_void_return}}*void*{{/is_void_return}}{{^is_void_return}}{{#is_data_buffer}}{{#data_buffer_type}}[{{> type}}](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/{{> type}}){{/data_buffer_type}}{{/is_data_buffer}}{{^is_data_buffer}}{{#is_generator}}Generator<{{#generator_type}}{{#yield_type}}{{> type_with_links}}{{/yield_type}}, {{#return_type}}{{> type_with_links}}{{/return_type}}, {{#next_type}}{{> type_with_links}}{{/next_type}}{{/generator_type}}>{{/is_generator}}{{^is_generator}}{{#is_map}}Record<{{#key_type}}{{> type_with_links}}{{/key_type}}, {{#value_type}}{{> type_with_links}}{{#is_optional_type}}{{#optional_type}} | *undefined*{{/optional_type}}{{/is_optional_type}}{{/value_type}}>{{/is_map}}{{^is_map}}{{#is_iterator_result}}IteratorResult&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator_result}}{{^is_iterator_result}}{{#is_iterator}}Iterator&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator}}{{^is_iterator}}{{#is_optional_type}}{{#optional_type}}{{> type_with_links}}{{/optional_type}}{{/is_optional_type}}{{^is_optional_type}}{{#is_variant}}{{#variant_types}}{{> type_with_links}}{{^is_last}} | {{/is_last}}{{/variant_types}}{{/is_variant}}{{^is_variant}}{{#is_promise}}Promise&lt;{{#promise_type}}{{> type_with_links}}{{/promise_type}}&gt;{{/is_promise}}{{^is_promise}}{{#is_array}}{{#element_type}}{{#is_optional_type}}{{#optional_type}}({{/optional_type}}{{/is_optional_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_optional_type}}{{#optional_type}} | *undefined*){{/optional_type}}{{/is_optional_type}}{{#is_variant}}){{/is_variant}}[]{{/element_type}}{{/is_array}}{{^is_array}}{{#is_undefined}}*undefined*{{/is_undefined}}{{^is_undefined}}{{#is_closure}}{{#closure_type}}({{#argument_types}}arg{{index}}: {{> type_with_links}}{{^is_last}}, {{/is_last}}{{/argument_types}}) => {{#return_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_variant}}){{/is_variant}}{{/return_type}}{{/closure_type}}{{^closure_type}}() => void{{/closure_type}}{{/is_closure}}{{^is_closure}}{{#argument_valid_values.length}}{{#argument_valid_values}}`'{{argument_valid_value}}'`{{^argument_valid_value_end}}, {{/argument_valid_value_end}}{{/argument_valid_values}}{{/argument_valid_values.length}}{{^argument_valid_values}}{{#is_bind_type}}[{{/is_bind_type}}*{{#from_module.is_external_module}}{{{from_module.name}}}.{{/from_module.is_external_module}}{{{name}}}*{{#is_bind_type}}]({{#from_module.is_external_module}}../../../{{{from_module.folder_path}}}/{{{from_module.filepath_name}}}/{{/from_module.is_external_module}}{{{name}}}.md){{/is_bind_type}}{{/argument_valid_values}}{{/is_closure}}{{/is_undefined}}{{/is_array}}{{/is_promise}}{{/is_variant}}{{/is_optional_type}}{{/is_iterator}}{{/is_iterator_result}}{{/is_map}}{{/is_generator}}{{/is_data_buffer}}{{/is_void_return}}
Loading