Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: get output value #334

Merged
merged 1 commit into from
Jun 12, 2024
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
3 changes: 2 additions & 1 deletion tools/src/tester/StoryOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class StoryOutputs {
}

get_output_value (chapter_id: string, output_name: string): any {
return this.outputs[chapter_id].get_output(output_name)
const output = this.outputs[chapter_id]
return output !== undefined ? output.get_output(output_name) : undefined
Comment on lines +34 to +35
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to just use optional chaining here:

Suggested change
const output = this.outputs[chapter_id]
return output !== undefined ? output.get_output(output_name) : undefined
return this.outputs[chapter_id]?.get_output(output_name)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't because this is a Record<string, ChapterOutput> and the type system is not smart enough to know that the value can be undefined.

}

resolve_params (parameters: Record<string, Parameter>): Record<string, Parameter> {
Expand Down
1 change: 1 addition & 0 deletions tools/tests/tester/story_outputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const story_outputs = new StoryOutputs({

test('resolve_string', () => {
expect(story_outputs.resolve_string('${chapter_id.x}')).toEqual(1)
expect(story_outputs.resolve_string('${invalid_id.x}')).toBeUndefined()
expect(story_outputs.resolve_string('some_str')).toEqual('some_str')
})

Expand Down
Loading