dsherret / ts-morph

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
https://ts-morph.com
MIT License
5.03k stars 196 forks source link

Missing types when resolving intersection (`string` | `null`) #1580

Open TomChv opened 1 month ago

TomChv commented 1 month ago

Describe the bug

Version: 24.0.0

I've hit this issue when I was introspecting some intersection type and couldn't actually resolve to the correct type.

For example: string | null only returns me string.

Here's an example of what ts-morph returns and the comparison with the actual TS compiler API:

// TS Compiler API
type: [ 'string | null' ]

// ts-morph
this.node.getType().getText(): string
testWithAllCheckerFunction: {
  isAnonymous: false,
  isAny: false,
  isArray: false,
  isBoolean: false,
  isBooleanLiteral: false,
  isClass: false,
  isClassOrInterface: false,
  isEnum: false,
  isEnumLiteral: false,
  isInterface: false,
  isIntersection: false,
  isLiteral: false,
  isNull: false,
  isNumber: false,
  isNumberLiteral: false,
  isObject: false,
  isString: true,
  isStringLiteral: false,
  isTemplateLiteral: false,
  isTuple: false,
  isUndefined: false,
  isUnion: false,
  isUnionOrIntersection: false,
  isUnknown: false
}

To Reproduce

I think it's a pretty much understandable issue without a repro, let me know if you absolutely need one.

Expected behavior

I thought ts-morph would at least returns true to isIntersection, I know resolving the value can be very complex but I don't understand why some checker actually return false except isString.

Let me know if you need more context/information. Happy to help also if you give me precise hints :)