You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I cannot resolve the type of an import to a concrete type. The type thats returned appears to always be 'any' regardless of what I do. Am I perhaps missing some initialization parameter?
To Reproduce
import{Project}from"ts-morph";exportconstproject=newProject({useInMemoryFileSystem: true,compilerOptions: {allowJs: true,jsx: ts.JsxEmit.ReactJSX,moduleResolution: ModuleResolutionKind.Bundler,esModuleInterop: true,resolveJsonModule: true,declaration: true,declarationMap: true,}});// or createProjectSyncconsole.log('project',project);exportconstfiles: Record<string,string>={'/MyClass.tsx': ` import MyButton from 'MyButton'; import {View} from 'react-native'; export default function MyContainer(){ return ( <View> <MyButton /> <MyButton /> </View> ); } `,'/MyButton.tsx': ` import { Button } from 'react-native'; export default function MyButton(){ return ( <Button title=\"abc123\" onPress={() => alert('pressed!')} /> ); }; '/jsfile.d.ts': `exportdeclaretypeMyComponentProps={name: string};exportdeclarefunctionMyComponent(props: MyComponentProps): number;`, '/jsfile.js': `exportfunctionMyComponent(props){return5;};
`,};constfileMap=Object.fromEntries(Object.entries(files).map(([file,data])=>{return[file,project.createSourceFile(file,data,{overwrite: true})];}));project.resolveSourceFileDependencies();constmyClassFile=fileMap['/MyClass.tsx'];myClassFilefile.getImportDeclarations().forEach((importDeclaration)=>{constdefaultImport=importDeclaration.getImportClause()?.getDefaultImport();console.log('default import:',defaultImport,defaultImport&&defaultImport.getType().getText());});// I would expect the console log to output some type that isnt 'any'
Expected behavior
I would expect the actual types to be resolved across different files. (I've tried this for .ts -> .ts files and .js -> .d.ts files). Please ket me know if theres something I need to do to enable this sort of type resolution (including adding type resolution for .d.ts files from .js files). Thanks!
The text was updated successfully, but these errors were encountered:
Describe the bug
Version: 23.0.0
I cannot resolve the type of an import to a concrete type. The type thats returned appears to always be 'any' regardless of what I do. Am I perhaps missing some initialization parameter?
To Reproduce
Expected behavior
I would expect the actual types to be resolved across different files. (I've tried this for .ts -> .ts files and .js -> .d.ts files). Please ket me know if theres something I need to do to enable this sort of type resolution (including adding type resolution for .d.ts files from .js files). Thanks!
The text was updated successfully, but these errors were encountered: