javascript - Typescript definitions for namespaced classes -
i'm attempting write typescript defs javascript library wrote. library looks like:
!function() { var mylib = {}; mylib.fruit = function() { // ... }; mylib.fruit.some_static_prop = 1; }(); the source comprised of multiple files concatenated -- minimal example, there's 1 file first 2 lines, 1 fruit, other last line.
fruit.d.ts:
declare module mylib { class fruit { static some_static_prop: number; } } in fruit.js (which again middle part of code pasted above), intellisense complains:
type '() => any' not assignable type 'typeof fruit'. property 'some_static_prop' missing in type '() => any'.
edit in concatenated file (e.g. what's pasted above), don't message.
if change fruit.js like
function fruit() { ... } without mylib namespace, there's no error either.
is there way avoid error in individual "class" files, or should ignore them?
in fruit.js (which again middle part of code pasted above), intellisense complains
because javascript, error type '() => any' not assignable type 'typeof fruit'. property 'some_static_prop' missing in type '() => any'. based on inferred type of variable.
solutions:
either:
- convert
.jsfile.tscan use type annotations , type assertions massage types - ignore error .js file , move on till time convert
.ts.
Comments
Post a Comment