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.

bug: Optional values in fixed length arrays not supported

See original GitHub issue

Command

yarn ts-interface-builder src/components/folder/folder/PreviewTextAdModel.ts

Error

yarn run v1.17.3
$ /Users/folder/folder/folder/folder/node_modules/.bin/ts-interface-builder src/components/folder/folder/PreviewTextAdModel.ts
/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:85
        throw new Error(`Node ${ts.SyntaxKind[node.kind]} not supported by ts-interface-builder: ` +
        ^

Error: Node JSDocNullableType not supported by ts-interface-builder: string?
    at Compiler.compileNode (/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:85:15)
    at Array.map (<anonymous>)
    at Compiler._compileTupleTypeNode (/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:148:43)
    at Compiler.compileNode (/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:51:55)
    at Compiler.compileOptType (/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:89:32)
    at Compiler._compilePropertySignature (/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:101:27)
    at Compiler.compileNode (/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:45:63)
    at /Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:167:30
    at Array.map (<anonymous>)
    at Compiler._compileInterfaceDeclaration (/Users/folder/folder/folder/folder/node_modules/ts-interface-builder/dist/index.js:167:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Interface

interface PreviewTextAdModel {
  finalUrl: string;
  host: string;
  headlines: [string, string, string?];
  paths: [string?, string?];
  descriptions: [string, string?];
}

Problem

[string, string, string?] => 0: string, 1: string, 2: string or undefined

Current “workaround”

interface PreviewTextAdModel {
  finalUrl: string;
  host: string;
  headlines: [string, string] | [string, string, string];
  paths: [] | [string] | [string, string];
  descriptions: [string] | [string, string];
}

Produces

PreviewTextAdModel-ti.ts

/**
 * This module was automatically generated by `ts-interface-builder`
 */
import * as t from 'ts-interface-checker';
// tslint:disable:object-literal-key-quotes

export const PreviewTextAdModel = t.iface([], {
  finalUrl: 'string',
  host: 'string',
  headlines: t.union(t.tuple('string', 'string'), t.tuple('string', 'string', 'string')),
  paths: t.union(t.tuple(), t.tuple('string'), t.tuple('string', 'string')),
  descriptions: t.union(t.tuple('string'), t.tuple('string', 'string'))
});

const exportedTypeSuite: t.ITypeSuite = {
  PreviewTextAdModel
};
export default exportedTypeSuite;

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dsagalcommented, Aug 27, 2019

Just published also

1reaction
dsagalcommented, Aug 27, 2019

Just published v0.2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does clang complain about using variable-length arrays ...
- where the VLA-support is optional, support variable length arrays without exception. Why do I still get this warning for using a VLA...
Read more >
Array declaration - cppreference.com
Zero-length array declarations are not allowed, even though some compilers offer them as extensions (typically as a pre-C99 implementation of ...
Read more >
RangeError: invalid array length - JavaScript - MDN Web Docs
The JavaScript exception "Invalid array length" occurs when specifying an array length that is either negative, a floating number or exceeds ...
Read more >
Constants, fixed-length strings, arrays, user-defined types, and ...
This error has the following causes and solutions: You declared a Public constant in an object module. Although you can't declare a Public ......
Read more >
Variable Length Arrays in C/C++ - GeeksforGeeks
Variable length arrays is a feature where we can allocate an auto array (on stack) of variable size. It can be used in...
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