Skip to content

Improve type support for ts #645 #646

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Feliz.CompilerPlugins/AstUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ open System.Text.RegularExpressions
let cleanFullDisplayName str =
Regex.Replace(str, @"`\d+", "").Replace(".", "_")

let makeIdent name: Fable.Ident =
let makeIdent _type name: Fable.Ident =
{ Name = name
Type = Fable.Any
Type = _type
IsCompilerGenerated = true
IsThisArgument = false
IsMutable = false
Expand All @@ -22,7 +22,7 @@ let makeUniqueIdent (name: string) =
if i < 0
then "Z" + (abs i).ToString("X")
else i.ToString("X")
"$" + name + (Guid.NewGuid().GetHashCode() |> hashToString) |> makeIdent
"$" + name + (Guid.NewGuid().GetHashCode() |> hashToString) |> makeIdent Fable.Any

let makeValue r value =
Fable.Value(value, r)
Expand Down
8 changes: 7 additions & 1 deletion Feliz.CompilerPlugins/ReactComponent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ type ReactComponentAttribute(?exportDefault: bool, ?import: string, ?from:string
else
// rewrite all other arguments into getters of a single props object
// TODO: transform any callback into into useCallback(callback) to stabilize reference
let propsArg = AstUtils.makeIdent (sprintf "%sInputProps" (AstUtils.camelCase decl.Name))
let propsArg =
let type_ =
let fieldNames, genericArgs = decl.Args |> List.map (fun arg -> arg.DisplayName, arg.Type) |> List.unzip
Fable.Type.AnonymousRecordType(Array.ofList fieldNames, genericArgs, false)
let name = sprintf "%sInputProps" (AstUtils.camelCase decl.Name)
AstUtils.makeIdent type_ name

let propBindings =
([], decl.Args) ||> List.fold (fun bindings arg ->
let getterKey = if arg.DisplayName = "key" then "$key" else arg.DisplayName
Expand Down