swift-syntax extension to infer types from expressions based on literal information.
Implemented as an extension of the ExprSyntaxProtocol
.
The type inferred from literal information can be obtained from the inferredType
property.
import SwiftSyntax
import SwiftSyntaxBuilder
import LiteralTypeInference
let expr: ExprSyntax = """
[
"item1": [
(1, 2.0, "3", true),
(1.0, 2, "7", false),
(nil, nil, nil, false)
],
"item2": [],
"item3": [
(1, 2, "3", true)
]
]
"""
// Get the type of expr from the `inferredType` property
let type = expr.inferredType
print(type?.formatted().description)
// => [String: [(Double?, Double?, String?, Bool)]]
LiteralTypeInference is released under the MIT License. See LICENSE