Skip to content

Add function type info#281

Merged
waynemwashuma merged 4 commits into
wimaengine:devfrom
waynemwashuma:type-functions
Mar 12, 2026
Merged

Add function type info#281
waynemwashuma merged 4 commits into
wimaengine:devfrom
waynemwashuma:type-functions

Conversation

@waynemwashuma
Copy link
Copy Markdown
Collaborator

@waynemwashuma waynemwashuma commented Mar 12, 2026

Objective

Add function type information support to the reflect module, enabling the reflection system to track and query function parameter and return types.

Solution

Introduced a new FunctionInfo class that extends TypeInfo to store function signature metadata. This class provides:

  • Storage of parameter types as a readonly array of TypeId
  • Storage of return type as a TypeId
  • Methods to retrieve individual parameters by index, get all parameters, and get the return type

Additionally, added a typeidFunction utility that generates proper type IDs for function signatures in the format fn(param1,param2,...):returnType.

Extended the type system by adding the TupleFnConstructor type definition to properly represent parameter type tuples in a type-safe manner.

Showcase

import { FunctionInfo, typeid, typeidFunction } from '@reflect'

// Create function type info
const functionInfo = new FunctionInfo(
  [typeid(Number), typeid(String)], 
  typeid(Boolean)
)

// Access parameter information
const firstParam = functionInfo.getParameter(0)  // Returns typeid(Number)
const allParams = functionInfo.getParameters()    // Returns all parameter types
const returnType = functionInfo.getReturnType()   // Returns typeid(Boolean)

// Generate type IDs for functions
function myFunction(a, b) {
  return true
}
const typeId = typeidFunction(myFunction, [Number, String], Boolean)

Migration guide

No breaking changes. This is a pure enhancement to the reflect module that adds new functionality without modifying existing APIs.

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Mar 12, 2026
@waynemwashuma waynemwashuma merged commit ade3c33 into wimaengine:dev Mar 12, 2026
7 checks passed
@waynemwashuma waynemwashuma deleted the type-functions branch March 12, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:reflect type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant