question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type.getProperties() throws TypeError

See original GitHub issue

Describe the bug Version: 14.1.0

Type.getProperties() throws the following error:

/Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/compiler/common/Symbol.js:94
        return this.compilerSymbol.declarations.map(function (d) { return _this.context.compilerFactory.getNodeFromCompilerNode(d, _this.context.compilerFactory.getSourceFileForNode(d)); });
                                                ^
TypeError: Cannot read property 'map' of undefined
    at Symbol.getDeclarations (/Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/compiler/common/Symbol.js:94:49)
    at new Symbol (/Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/compiler/common/Symbol.js:18:14)
    at /Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/factories/CompilerFactory.js:388:74
    at WeakCache.getOrCreate (/Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/utils/collections/WeakCache.js:14:20)
    at CompilerFactory.getSymbol (/Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/factories/CompilerFactory.js:388:33)
    at /Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/compiler/type/Type.js:130:106
    at Array.map (<anonymous>)
    at Type.getProperties (/Users/rhys/Projects/ts-simple-ast-test/node_modules/ts-simple-ast/dist/compiler/type/Type.js:130:50)
    at Object.<anonymous> (/Users/rhys/Projects/ts-simple-ast-test/pick.ts:53:6)
    at Module._compile (module.js:641:30)

To Reproduce

I’ve created a repo that can reproduce the error with full code to reproduce issue.

Run yarn install && yarn run pick.

Strangely it only fails if I set the config file which I copied from my other project.

Essence of the issue:

const sourceFile = project.createSourceFile(
    "src/index.ts", `
    interface Foo {
        a: number,
        b: number,
    }
    export type Picked = Pick<Foo, "a">
`);

const type = sourceFile.getTypeAliases()[0].getType();

type.getProperties() // <-- THIS LINE THROWS

Expected behavior

Return an array of properties.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rhys-vdwcommented, Aug 22, 2018

I believe you’re on the right track…

Oh, yeah. Awesome. It does do what I want. Misinterpreted the change. Think I’m close to finishing my lib now.

0reactions
dsherretcommented, Aug 22, 2018

Yeah it was because that property (this.compilerSymbol.declarations) was nullable when the compiler api’s definitions say it won’t be. I’m too lazy to create a simple reproducible example and report it to them at the moment though (it will probably be fixed sometime in the future anyway because they’ve been doing some analysis on where they do suspicious non-null assertions).

What do you mean by handling the properties of that? For that, I believe you’re on the right track and type.getProperties() should return that single a property as is happening in this test.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type.GetProperties() not working - Stack Overflow
// Well this works, so I know there is a property there. var clearly_a_property = Strings.home_cancel; // Yet none of this works var...
Read more >
ContactsManager.getProperties() - Web APIs | MDN
The getProperties() method of the ContactsManager interface returns a Promise which ... Otherwise, select() might throw a TypeError .
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
TypeError - what causes them? - Vaadin
I've also added the browser's debugger results (see image) that shows the function throwing a TypeError. This is happening randomly in both development...
Read more >
How do I solve "object does not match target type." error as ...
throw new FormatException(message); } return base. ... GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found