Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Add Luau types #36

Merged
merged 10 commits into from
Aug 6, 2022
Merged

Add Luau types #36

merged 10 commits into from
Aug 6, 2022

Conversation

JohnnyMorganz
Copy link
Contributor

@JohnnyMorganz JohnnyMorganz commented Jul 16, 2022

Adds Luau types to (most) of the functions.

This is best effort, some things cannot currently be typed (correctly) yet, but we cover the most common uses. This shouldn't emit any false positives.

The following types are exported:

  • Hooks, the second parameter of a functional component. Contains useState etc.
  • RenderFunction<Props>, the functional component which has been "hook-ified"
  • HookOptions<Props>, the options passed in Hooks.new

defined as

export type Hooks = -- inferred --
export type HookOptions<Props> = {
	name: string?,
	defaultProps: { [string]: any }?,
	componentType: string?,
	validateProps: ((props: Props) -> (boolean, string?))?,
	[string]: { NO_EXTRA_ARGS: never },
}
export type RenderFunction<Props> = (props: Props, hooks: Hooks) -> any

The following are now correctly typed:

  • The functional component passed to Hooks.new(Roact)(component, options): it takes props and hooks, and should return one value [we currently cannot enforce that one value is a RoactComponent]
  • The options passed to the above
  • useState
  • useEffect
  • useValue (auto inferred type)
  • useCallback
  • useMemo
  • useReducer

useContext, useBinding and Roact are unfortunately not currently typed as we do not have enough info about them.

Adding these types provide improved intellisense when using Luau LSP / Roblox Studio

Example Screenshots

image
image
image
image
image

@Kampfkarren
Copy link
Owner

CHANGELOG please

src/createUseBinding.lua Show resolved Hide resolved
src/createUseMemo.lua Outdated Show resolved Hide resolved
src/createUseState.lua Outdated Show resolved Hide resolved
@JohnnyMorganz
Copy link
Contributor Author

@Kampfkarren any movement on this?

@Kampfkarren
Copy link
Owner

I forgot. I'll just assume these are correct :P

@Kampfkarren Kampfkarren merged commit bcdf9db into Kampfkarren:main Aug 6, 2022
@fewkz
Copy link

fewkz commented Aug 28, 2022

Can there be a wally release for this? This would be incredibly useful

@JohnnyMorganz JohnnyMorganz deleted the types branch August 28, 2022 18:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants