p-x9/swift-literal-type-inference
swift-syntax extension to infer types from expressions based on literal information.
Usage
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)]]License
LiteralTypeInference is released under the MIT License. See LICENSE
Package Metadata
Repository: p-x9/swift-literal-type-inference
Default branch: main
README: README.md