Here you go
    
    
    import macros, options
    
    type
      ssnType = Option[int]
    
    type
      Person = object
        age: Option[int]
        ssn: ssnType
    
    proc isOptionInt(x: NimNode): bool =
      sameType(x, getType(Option[int]))
    
    macro checkOptionInt(x: typed): untyped =
      result = newLit(x.isOptionInt)
    
    echo checkOptionInt(typeof(Person().ssn))
    
    
    Run

Note that you can turn a typedesc into a NimNode with `getType`, but there is 
no way to turn a NimNode representing a type back to a typedesc, and the 
corresponding feature request was closed 
([https://github.com/nim-lang/Nim/issues/6785)](https://github.com/nim-lang/Nim/issues/6785\)),
 so keep your typedescs around as long as possible.

Reply via email to