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.

Property X never defined on Y

See original GitHub issue

I’m running into this issue,

// index.js
import Type from './Type'

const t = new Type()
t.fromXML('Hello world', { name: 'test', optional: false })
console.log(t.type)
// Type.js
/**
 * A representation of a type.
 * @extends {typal.Type}
 */
export default class Type {
  fromXML(content, props) {
    this.type = props.name
    this.desc = content
  }
}
// depack/prop/externs.js
/** @const */
var typal = {}
/**
 * @typedef {{ type: string, desc: string }}
 */
typal.Type

I’m pretty sure if something extends an extern, it should preserve its own methods as well.

-jar compiler.jar --compilation_level ADVANCED \
--language_out ECMASCRIPT_2017 \
--formatting PRETTY_PRINT --externs depack/prop/externs.js \
--module_resolution NODE \
--js depack/prop/index.js depack/prop/Type.js 

Compiles fine though

class a {
}
;const b = new a;
b.type = "test";
b.desc = "Hello world";
console.log(b.type);

Don’t want the warning though.

depack/prop/index.js:4: WARNING - Property fromXML never defined on Type
t.fromXML('Hello world', { name: 'test', optional: false })
  ^^^^^^^

0 error(s), 1 warning(s), 87.0% typed

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
brad4dcommented, Apr 8, 2019

@zavr-1 I’m glad you’ve found a solution.

0reactions
zavr-1commented, Apr 8, 2019

hi yeah i’ve figured it out I could do that thank you, did something like that (without externs, because the whole point of externs was to avoid an error saying that I cannot assign to uninitialised properties on a structure, so I just initialise them all in the constructor to null. , please feel free to close this.

/**
 * A representation of a type.
 */
export default class Type {
  constructor() {
   /**
     * The name of the type.
     * @type {?string}
     */
    this.name = null
    /** @type {?string} */
    this.type = null
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

"Property never defined on any type in the program" error ...
A workaround is to avoid typedefs in externs like this; e.g. here I'm declaring a non-existent constructor purely for type hinting: /** @ ......
Read more >
error TS2339: Property 'x' does not exist on type 'Y'
I'm no expert in Typescript, but I think the main problem is the way of accessing data. Seeing how you described your Images...
Read more >
Property is missing in type 'X' but required in type 'Y' | bobbyhadz
The TypeScript error "Property is missing in type but required in type" occurs when we do not set all of the properties an...
Read more >
TypeError: can't define property "x": "obj" is not extensible
The JavaScript exception "can't define property "x": "obj" is not extensible" occurs when Object.preventExtensions() marked an object as no ...
Read more >
Documentation - Everyday Types - TypeScript
To define an object type, we simply list its properties and their types. ... with a type with two properties - x and...
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