Skip to content

Wrong type for useTween subProps #11

@gavinostler

Description

@gavinostler

Under the new type checker (which should, in theory, be reported by the old type checker, but isn't), useTween reports a TypeError if start and info are missing:

TypeError: Table type '{ target: number }' not compatible with type 'TweenProperties<number>' because the former is missing fields 'start', and 'info'

The implementation of the function implies that these fields can be left blank, but the TweenProperties<T> type requires the properties to be non-nil. The documentation also agrees with this, requiring start and info. I've never used these two properties; instead, I only specify target, so I don't have to pass in the current state of the tween. This has worked in the past when I was using the old type checker, since it didn't pick this up.

The current implementation is:

start = function(subProps: Tween.TweenProperties<T>, immediate: boolean?)
	assert(typeof(subProps) == "table", "useTween expects a table of properties")

	tween.props.info = subProps.info or tween.props.info
	tween.props.start = subProps.start or binding:getValue()
	tween.props.target = subProps.target or tween.props.target
	tween.props.startImmediate = subProps.startImmediate or tween.props.startImmediate
	tween.props.delay = subProps.delay or tween.props.delay
	tween:Play(subProps.start or binding:getValue(), immediate)
end

https://github.com/OutOfBears/react-flow/blob/c86cc0c11c44359bf2f048c42348fe6aafd49dd4/src/Hooks/useTween.lua#L17C4-L26C8

The documentation should either be updated to specify that all the properties are required (as per the type) or the type should be revised to not require properties like info, start, target, startImmediate, and delay.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions