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

Mark Spawning.directions as optional #244

Merged
merged 2 commits into from
Aug 16, 2023

Conversation

tiennou
Copy link
Contributor

@tiennou tiennou commented Aug 11, 2023

This property is only defined if it was passed as spawn options, or it got set through Spawn.spawning.setDirections. Otherwise it'll be undefined and the creep will default to [TOP].

Fixes #243.

Checklists

  • Test passed
  • Coding style (indentation, etc)
  • Edits have been made to src/ files not index.d.ts
  • Run npm run dtslint to update index.d.ts

This property is only defined if it was passed as spawn options, or
it got set through `Spawn.spawning.setDirections`. Otherwise it'll be
`undefined` and the creep will default to `[TOP]`.
@DiamondMofeng
Copy link
Member

Thank you❤️. Anyway I think Typescript's Optional Propertiy Modifier ?: is more suitable in this case.

interface A {
  p?: number;
}

let a: A = {} // OK
interface B {
  p: number | undefined | null
}

let b: B = {} // Error: Property 'p' is missing in type '{}' but required in type 'B'.

Although we won't create a Spawning object, the former case expresses better.

You can accept suggested changes on the website. Then we are ready to go🚀

dist/index.d.ts Outdated Show resolved Hide resolved
src/spawn.ts Outdated Show resolved Hide resolved
@tiennou
Copy link
Contributor Author

tiennou commented Aug 16, 2023

There you go!

Copy link
Member

@DiamondMofeng DiamondMofeng left a comment

Choose a reason for hiding this comment

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

LGTM

@DiamondMofeng DiamondMofeng merged commit 1c78130 into screepers:master Aug 16, 2023
@tiennou tiennou deleted the fix/spawning-directions branch January 15, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spawning.directions can be undefined
2 participants