Documentation
¶
Index ¶
- func CollectAllCallSignatures(typeChecker *checker.Checker, t *checker.Type) []*checker.Signature
- func ComparePaths(a string, b string, program *compiler.Program) int
- func CreateCompilerHost(cwd string, fs vfs.FS) compiler.CompilerHost
- func CreateProgram(singleThreaded bool, fs vfs.FS, cwd string, tsconfigPath string, ...) (*compiler.Program, error)
- func Every[T any](slice []T, f func(T) bool) bool
- func Filter[T any](slice []T, f func(T) bool) []T
- func FilterIndex[T any](slice []T, f func(T, int, []T) bool) []T
- func Flatten[T any](array [][]T) []T
- func GetCallSignatures(typeChecker *checker.Checker, t *checker.Type) []*checker.Signature
- func GetCommentsInRange(sourceFile *ast.SourceFile, inRange core.TextRange) iter.Seq[ast.CommentRange]
- func GetConstrainedTypeAtLocation(typeChecker *checker.Checker, node *ast.Node) *checker.Type
- func GetConstraintInfo(typeChecker *checker.Checker, t *checker.Type) (constraintType *checker.Type, isTypeParameter bool)
- func GetConstructSignatures(typeChecker *checker.Checker, t *checker.Type) []*checker.Signature
- func GetContextualType(typeChecker *checker.Checker, node *ast.Node) *checker.Type
- func GetDeclaration(typeChecker *checker.Checker, node *ast.Node) *ast.Declaration
- func GetEnumLiterals(t *checker.Type) []*checker.Type
- func GetEnumTypes(typeChecker *checker.Checker, t *checker.Type) []*checker.Type
- func GetForStatementHeadLoc(sourceFile *ast.SourceFile, node *ast.Node) core.TextRange
- func GetHeritageClauses(node *ast.Node) *ast.NodeList
- func GetNumberIndexType(typeChecker *checker.Checker, t *checker.Type) *checker.Type
- func GetParentFunctionNode(node *ast.Node) *ast.Node
- func GetThisExpression(node *ast.Node) *ast.Node
- func GetTypeName(typeChecker *checker.Checker, t *checker.Type) string
- func GetWellKnownSymbolPropertyOfType(t *checker.Type, name string, typeChecker *checker.Checker) *ast.Symbol
- func HasCommentsInRange(sourceFile *ast.SourceFile, inRange core.TextRange) bool
- func IncludesModifier(node interface{ ... }, modifier ast.Kind) bool
- func IntersectionTypeParts(t *checker.Type) []*checker.Type
- func IsAnyBuiltinSymbolLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type) bool
- func IsArrayMethodCallWithPredicate(typeChecker *checker.Checker, node *ast.CallExpression) bool
- func IsBooleanLiteralType(t *checker.Type) bool
- func IsBuiltinSymbolLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type, ...) bool
- func IsBuiltinSymbolLikeRecurser(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type, ...) bool
- func IsBuiltinTypeAliasLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type, ...) bool
- func IsCallback(typeChecker *checker.Checker, param *ast.Symbol, node *ast.Node) bool
- func IsErrorLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type) bool
- func IsFalseLiteralType(t *checker.Type) bool
- func IsHigherPrecedenceThanAwait(node *ast.Node) bool
- func IsIntersectionType(t *checker.Type) bool
- func IsIntrinsicErrorType(t *checker.Type) bool
- func IsIntrinsicType(t *checker.Type) bool
- func IsIntrinsicVoidType(t *checker.Type) bool
- func IsObjectType(t *checker.Type) bool
- func IsParenlessArrowFunction(node *ast.Node) bool
- func IsPromiseConstructorLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type) bool
- func IsPromiseLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type) bool
- func IsReadonlyErrorLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type) bool
- func IsReadonlyTypeLike(program *compiler.Program, typeChecker *checker.Checker, t *checker.Type, ...) bool
- func IsRestParameterDeclaration(decl *ast.Declaration) bool
- func IsSourceFileDefaultLibrary(program *compiler.Program, file *ast.SourceFile) bool
- func IsStrWhiteSpace(r rune) bool
- func IsStrictCompilerOptionEnabled(options *core.CompilerOptions, option core.Tristate) bool
- func IsStrongPrecedenceNode(innerNode *ast.Node) bool
- func IsSymbolFlagSet(symbol *ast.Symbol, flag ast.SymbolFlags) bool
- func IsSymbolFromDefaultLibrary(program *compiler.Program, symbol *ast.Symbol) bool
- func IsThenableType(typeChecker *checker.Checker, node *ast.Node, t *checker.Type) bool
- func IsTrueLiteralType(t *checker.Type) bool
- func IsTypeAnyArrayType(t *checker.Type, typeChecker *checker.Checker) bool
- func IsTypeAnyType(t *checker.Type) bool
- func IsTypeFlagSet(t *checker.Type, flags checker.TypeFlags) bool
- func IsTypeParameter(t *checker.Type) bool
- func IsTypeUnknownArrayType(t *checker.Type, typeChecker *checker.Checker) bool
- func IsTypeUnknownType(t *checker.Type) bool
- func IsUnionType(t *checker.Type) bool
- func IsUnsafeAssignment(t *checker.Type, receiverT *checker.Type, typeChecker *checker.Checker, ...) (receiver *checker.Type, sender *checker.Type, unsafe bool)
- func Map[T, U any](slice []T, f func(T) U) []U
- func NewOverlayVFS(baseFS vfs.FS, virtualFiles map[string]string) vfs.FS
- func NewOverlayVFSForFile(filePath string, source string) vfs.FS
- func Ref[T any](a T) *T
- func Some[T any](slice []T, f func(T) bool) bool
- func TrimNodeTextRange(sourceFile *ast.SourceFile, node *ast.Node) core.TextRange
- func TypeMatchesSomeSpecifier(t *checker.Type, specifiers []TypeOrValueSpecifier, inlineSpecifiers []string, ...) bool
- func TypeRecurser(t *checker.Type, predicate func(t *checker.Type) bool) bool
- func UnionTypeParts(t *checker.Type) []*checker.Type
- type ConstraintTypeInfo
- type DiscriminatedAnyType
- type MemberNameType
- type OverlayVFS
- func (vfs *OverlayVFS) DirectoryExists(path string) bool
- func (vfs *OverlayVFS) FileExists(path string) bool
- func (vfs *OverlayVFS) GetAccessibleEntries(path string) (result vfs.Entries)
- func (vfs *OverlayVFS) ReadFile(path string) (contents string, ok bool)
- func (vfs *OverlayVFS) Realpath(path string) string
- func (vfs *OverlayVFS) Remove(path string) error
- func (vfs *OverlayVFS) Stat(path string) vfs.FileInfo
- func (vfs *OverlayVFS) UseCaseSensitiveFileNames() bool
- func (vfs *OverlayVFS) WalkDir(root string, walkFn vfs.WalkDirFunc) error
- func (vfs *OverlayVFS) WriteFile(path string, data string, writeByteOrderMark bool) error
- type Set
- type TypeAwaitable
- type TypeOrValueSpecifier
- type TypeOrValueSpecifierFrom
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectAllCallSignatures ¶
ex. getCallSignaturesOfType
func CreateCompilerHost ¶
func CreateCompilerHost(cwd string, fs vfs.FS) compiler.CompilerHost
func CreateProgram ¶
func FilterIndex ¶
Source: typescript-go/internal/core/core.go
func GetCallSignatures ¶
func GetCommentsInRange ¶
func GetCommentsInRange(sourceFile *ast.SourceFile, inRange core.TextRange) iter.Seq[ast.CommentRange]
func GetConstraintInfo ¶
func GetConstraintInfo( typeChecker *checker.Checker, t *checker.Type, ) (constraintType *checker.Type, isTypeParameter bool)
*
- Returns whether the type is a generic and what its constraint is. *
- If the type is not a generic, `isTypeParameter` will be `false`, and
- `constraintType` will be the same as the input type. *
- If the type is a generic, and it is constrained, `isTypeParameter` will be
- `true`, and `constraintType` will be the constraint type. *
- If the type is a generic, but it is not constrained, `constraintType` will be
- `undefined` (rather than an `unknown` type), due to https://github.com/microsoft/TypeScript/issues/60475 *
- Successor to {@link getConstrainedTypeAtLocation} due to https://github.com/typescript-eslint/typescript-eslint/issues/10438 *
- This is considered internal since it is unstable for now and may have breaking changes at any time.
- Use at your own risk. *
- @internal *
func GetConstructSignatures ¶
func GetContextualType ¶
*
- Returns the contextual type of a given node.
- Contextual type is the type of the target the node is going into.
- i.e. the type of a called function's parameter, or the defined type of a variable declaration
func GetEnumLiterals ¶
*
- Retrieve only the Enum literals from a type. for example:
- - 123 --> []
- - {} --> []
- - Fruit.Apple --> [Fruit.Apple]
- - Fruit.Apple | Vegetable.Lettuce --> [Fruit.Apple, Vegetable.Lettuce]
- - Fruit.Apple | Vegetable.Lettuce | 123 --> [Fruit.Apple, Vegetable.Lettuce]
- - T extends Fruit --> [Fruit]
func GetEnumTypes ¶
*
- A type can have 0 or more enum types. For example:
- - 123 --> []
- - {} --> []
- - Fruit.Apple --> [Fruit]
- - Fruit.Apple | Vegetable.Lettuce --> [Fruit, Vegetable]
- - Fruit.Apple | Vegetable.Lettuce | 123 --> [Fruit, Vegetable]
- - T extends Fruit --> [Fruit]
func GetForStatementHeadLoc ¶
*
- Gets the location of the head of the given for statement variant for reporting. *
- - `for (const foo in bar) expressionOrBlock`
- ^^^^^^^^^^^^^^^^^^^^^^ *
- - `for (const foo of bar) expressionOrBlock`
- ^^^^^^^^^^^^^^^^^^^^^^ *
- - `for await (const foo of bar) expressionOrBlock`
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
- - `for (let i = 0; i < 10; i++) expressionOrBlock`
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
func GetNumberIndexType ¶
func GetTypeName ¶
*
- Get the type name of a given type.
- @param typeChecker The context sensitive TypeScript TypeChecker.
- @param type The type to get the name of.
func HasCommentsInRange ¶
func HasCommentsInRange(sourceFile *ast.SourceFile, inRange core.TextRange) bool
func IncludesModifier ¶
func IncludesModifier(node interface{ Modifiers() *ast.ModifierList }, modifier ast.Kind) bool
func IsAnyBuiltinSymbolLike ¶
func IsArrayMethodCallWithPredicate ¶
func IsArrayMethodCallWithPredicate( typeChecker *checker.Checker, node *ast.CallExpression, ) bool
func IsBooleanLiteralType ¶
func IsBuiltinSymbolLike ¶
func IsBuiltinTypeAliasLike ¶
func IsCallback ¶
func IsFalseLiteralType ¶
func IsIntersectionType ¶
func IsIntrinsicErrorType ¶
func IsIntrinsicType ¶
func IsIntrinsicVoidType ¶
func IsObjectType ¶
func IsPromiseConstructorLike ¶
func IsPromiseConstructorLike( program *compiler.Program, typeChecker *checker.Checker, t *checker.Type, ) bool
*
- @example
- ```ts
- const value = Promise
- value.reject
- // ^ PromiseConstructorLike
- ```
func IsPromiseLike ¶
*
- @example
- ```ts
- class DerivedClass extends Promise<number> {}
- DerivedClass.reject
- // ^ PromiseLike
- ```
func IsReadonlyErrorLike ¶
func IsReadonlyErrorLike( program *compiler.Program, typeChecker *checker.Checker, t *checker.Type, ) bool
*
- @example
- ```ts
- type T = Readonly<Error>
- // ^ ReadonlyErrorLike
- ```
func IsReadonlyTypeLike ¶
func IsReadonlyTypeLike( program *compiler.Program, typeChecker *checker.Checker, t *checker.Type, predicate func(subType *checker.Type) bool, ) bool
*
- @example
- ```ts
- type T = Readonly<{ foo: 'bar' }>
- // ^ ReadonlyTypeLike
- ```
func IsRestParameterDeclaration ¶
func IsRestParameterDeclaration(decl *ast.Declaration) bool
func IsSourceFileDefaultLibrary ¶
func IsSourceFileDefaultLibrary(program *compiler.Program, file *ast.SourceFile) bool
func IsStrWhiteSpace ¶
func IsStrictCompilerOptionEnabled ¶
func IsStrictCompilerOptionEnabled( options *core.CompilerOptions, option core.Tristate, ) bool
*
- Checks if a given compiler option is enabled, accounting for whether all flags
- (except `strictPropertyInitialization`) have been enabled by `strict: true`.
- @category Compiler Options
- @example
- ```ts
- const optionsLenient = {
- noImplicitAny: true,
- }; *
- isStrictCompilerOptionEnabled(optionsLenient, "noImplicitAny"); // true
- isStrictCompilerOptionEnabled(optionsLenient, "noImplicitThis"); // false
- ```
- @example
- ```ts
- const optionsStrict = {
- noImplicitThis: false,
- strict: true,
- }; *
- isStrictCompilerOptionEnabled(optionsStrict, "noImplicitAny"); // true
- isStrictCompilerOptionEnabled(optionsStrict, "noImplicitThis"); // false
- ```
func IsStrongPrecedenceNode ¶
func IsSymbolFlagSet ¶
func IsSymbolFlagSet(symbol *ast.Symbol, flag ast.SymbolFlags) bool
func IsThenableType ¶
TODO(note): why there is no IntersectionTypeParts
func IsTrueLiteralType ¶
func IsTypeAnyType ¶
func IsTypeParameter ¶
func IsTypeUnknownType ¶
func IsUnionType ¶
func IsUnsafeAssignment ¶
func IsUnsafeAssignment( t *checker.Type, receiverT *checker.Type, typeChecker *checker.Checker, senderNode *ast.Node, ) (receiver *checker.Type, sender *checker.Type, unsafe bool)
*
- Does a simple check to see if there is an any being assigned to a non-any type. *
- This also checks generic positions to ensure there's no unsafe sub-assignments.
- Note: in the case of generic positions, it makes the assumption that the two types are the same. *
- @example See tests for examples *
- @returns false if it's safe, or an object with the two types if it's unsafe
func Map ¶
func Map[T, U any](slice []T, f func(T) U) []U
Source: typescript-go/internal/core/core.go
func TrimNodeTextRange ¶
Types ¶
type ConstraintTypeInfo ¶
type DiscriminatedAnyType ¶
type DiscriminatedAnyType uint8
const ( DiscriminatedAnyTypeAny DiscriminatedAnyType = iota DiscriminatedAnyTypePromiseAny DiscriminatedAnyTypeAnyArray DiscriminatedAnyTypeSafe )
func DiscriminateAnyType ¶
func DiscriminateAnyType( t *checker.Type, typeChecker *checker.Checker, program *compiler.Program, node *ast.Node, ) DiscriminatedAnyType
*
- @returns `DiscriminatedAnyTypeAny ` if the type is `any`, `DiscriminatedAnyTypeAnyArray` if the type is `any[]` or `readonly any[]`, `DiscriminatedAnyTypePromiseAny` if the type is `Promise<any>`,
* otherwise it returns `DiscriminatedAnyTypeSafe`.
type MemberNameType ¶
type MemberNameType uint8
const ( MemberNameTypePrivate MemberNameType = iota MemberNameTypeQuoted MemberNameTypeNormal MemberNameTypeExpression )
func GetNameFromMember ¶
func GetNameFromMember(sourceFile *ast.SourceFile, member *ast.Node) (string, MemberNameType)
*
- Gets a string name representation of the name of the given MethodDefinition
- or PropertyDefinition node, with handling for computed property names.
type OverlayVFS ¶
func (*OverlayVFS) DirectoryExists ¶
func (vfs *OverlayVFS) DirectoryExists(path string) bool
func (*OverlayVFS) FileExists ¶
func (vfs *OverlayVFS) FileExists(path string) bool
func (*OverlayVFS) GetAccessibleEntries ¶
func (vfs *OverlayVFS) GetAccessibleEntries(path string) (result vfs.Entries)
func (*OverlayVFS) ReadFile ¶
func (vfs *OverlayVFS) ReadFile(path string) (contents string, ok bool)
func (*OverlayVFS) Realpath ¶
func (vfs *OverlayVFS) Realpath(path string) string
func (*OverlayVFS) Remove ¶
func (vfs *OverlayVFS) Remove(path string) error
func (*OverlayVFS) UseCaseSensitiveFileNames ¶
func (vfs *OverlayVFS) UseCaseSensitiveFileNames() bool
func (*OverlayVFS) WalkDir ¶
func (vfs *OverlayVFS) WalkDir(root string, walkFn vfs.WalkDirFunc) error
type Set ¶
type Set[T comparable] struct { M map[T]struct{} }
func NewSetFromItems ¶
func NewSetFromItems[T comparable](items ...T) *Set[T]
func NewSetWithSizeHint ¶
func NewSetWithSizeHint[T comparable](hint int) *Set[T]
NewSetWithSizeHint creates a new Set with a hint for the number of elements it will contain.
type TypeAwaitable ¶
type TypeAwaitable int32
const ( TypeAwaitableAlways TypeAwaitable = iota TypeAwaitableNever TypeAwaitableMay )
func NeedsToBeAwaited ¶
type TypeOrValueSpecifier ¶
type TypeOrValueSpecifier struct { From TypeOrValueSpecifierFrom Name []string // Can be used when From == TypeOrValueSpecifierFromFile Path string // Can be used when From == TypeOrValueSpecifierFromPackage Package string }
type TypeOrValueSpecifierFrom ¶
type TypeOrValueSpecifierFrom uint8
const ( TypeOrValueSpecifierFromFile TypeOrValueSpecifierFrom = iota TypeOrValueSpecifierFromLib TypeOrValueSpecifierFromPackage )
Click to show internal directories.
Click to hide internal directories.