0

I have an interface in typescript

interface SomeInterface {
   words: string[];
}

I use typescript TypeChecker when compiling to check property types and skip those who are string[]. There is a method in Typescript package to check if node is of array type

function isArrayTypeNode(node: Node): node is ArrayTypeNode;

But is it possible also to check if it is string array?

Andyally
  • 863
  • 1
  • 9
  • 22
  • 1
    That interface declaration isn't valid TypeScript (it needs a name). How does that interface relate to the rest of the question? It has a `words` property of type `string[]` but the question seems to be about identifying `string[]` in the first place; are you trying to find things that can go into the `words` property? From where are you finding them? What is `ArrayTypeNode`? Could you [edit] this question to clarify what you're looking for (possibly by removing things which aren't being referred to)? – jcalz Mar 09 '22 at 14:29
  • The idea is that typescript during runtime checks all property types from interfaces to find out Date types only (needed to convert date string to date object during runtime). It does it by visiting every property type and when it visits array type node it checks every property of that arrays type (for example for array of SomeInterface[] it will check all properties of SomeInterface). However when it faces string[] array all properties/methods of string object which I want to skip as it gives infinite loop). – Andyally Mar 10 '22 at 08:06
  • Interfaces don't exist at runtime, so I'm still confused. And I still don't know what `ArrayTypeNode` is since it's not defined. Could you provide, in the question, a [mre] that demonstrates an actual issue (e.g., the infinite loop you're hitting into)? Ideally someone could paste the code into a standalone IDE like [The TypeScript Playground (link here!)](https://tsplay.dev/mqEzdm) and immediately get to work solving the problem without first needing to re-create it. So there should be no pseudocode, typos, unrelated errors, or undeclared types or values. – jcalz Mar 10 '22 at 14:31
  • I believe OP is referring to TypeChecker from the TypeScript compiler API: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API – lmonninger Dec 01 '22 at 18:22
  • @Andyally see if https://stackoverflow.com/questions/60610543/how-can-i-use-the-typescript-compiler-api-to-extract-the-type-of-an-array fits – lmonninger Dec 01 '22 at 18:43

0 Answers0