#Mapping type of nested function

1 messages · Page 1 of 1 (latest)

toxic sleet
#
--!strict

type InnerFunction = <U>(x: any | U) -> U


local function foo(): InnerFunction
    return function<U>(x: any | U): U
            return x
    end
end

local test = foo()("test") --unknown

does anyone know why test is unknown or how to map U out so it gets recognized by the typechecker

oblique needle
toxic sleet
# oblique needle U set x to any thats why remove x and keep U
--!strict

local stringTable = {
    hello = print("hello"),
    test = print("test"),
    wow = print("wow")
}

type StringTable = typeof(stringTable)
type Acceptance = keyof<StringTable>

type InnerFunction = <U>(x: Acceptance | U) -> index<StringTable, U>

local function foo(): InnerFunction
    return function<U>(x: Acceptance | U): index<StringTable, U>
            return x
    end
end

local test = foo()("test")

--local test: index<{
--    hello: nil,
--    test: nil,
--    wow: nil
--}, unknown>
-- now its unkown

any idea about this?

toxic sleet
#

ig