File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import ts from "typescript" ;
2- import { LiteralValue } from "@code0-tech/sagittarius-graphql-types" ;
3- import { createCompilerHost } from "../utils" ;
2+ import { DataType , LiteralValue } from "@code0-tech/sagittarius-graphql-types" ;
3+ import { createCompilerHost , getSharedTypeDeclarations } from "../utils" ;
44
55/**
66 * Extracts possible literal values from a type string to provide suggestions.
77 */
8- export const getValueSuggestions = ( type : string ) : LiteralValue [ ] => {
8+ export const getValueSuggestions = (
9+ type ?: string ,
10+ dataTypes ?: DataType [ ]
11+ ) : LiteralValue [ ] => {
912 if ( ! type ) return [ ] ;
1013
11- const sourceCode = `type T = ${ type } ; const val: T = {} as any;` ;
14+ const sourceCode = `
15+ ${ getSharedTypeDeclarations ( dataTypes ) }
16+ type T = ${ type } ; const val: T = {} as any;
17+ ` ;
1218 const fileName = "index.ts" ;
1319 const host = createCompilerHost ( fileName , sourceCode ) ;
1420 const sourceFile = host . getSourceFile ( fileName ) ! ;
Original file line number Diff line number Diff line change @@ -75,12 +75,12 @@ export const DEFAULT_COMPILER_OPTIONS: ts.CompilerOptions = {
7575/**
7676 * Extracts and returns common type and generic declarations from DATA_TYPES.
7777 */
78- export function getSharedTypeDeclarations ( dataTypes : DataType [ ] ) : string {
79- const genericDeclarations = Array . from ( new Set ( dataTypes . flatMap ( dt => dt . genericKeys || [ ] ) ) )
78+ export function getSharedTypeDeclarations ( dataTypes ? : DataType [ ] ) : string {
79+ const genericDeclarations = Array . from ( new Set ( dataTypes ? .flatMap ( dt => dt . genericKeys || [ ] ) ) )
8080 . map ( g => `type ${ g } = any;` )
8181 . join ( "\n" ) ;
8282
83- const typeAliasDeclarations = dataTypes . map ( dt =>
83+ const typeAliasDeclarations = dataTypes ? .map ( dt =>
8484 `type ${ dt . identifier } ${ dt . genericKeys ? `<${ dt . genericKeys . join ( "," ) } >` : "" } = ${ dt . type } ;`
8585 ) . join ( "\n" ) ;
8686
You can’t perform that action at this time.
0 commit comments