Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
This repository was archived by the owner on May 22, 2025. It is now read-only.

Tsickle does not support intersection types, causing errors in declaration files #1067

Closed
@engelsdamien

Description

@engelsdamien

This is related to #886, but in this case, when the type is declare'd, it means that some properties do not end up in externs files, causing them to be renamed by the Closure Compiler.

Typescript declarations:

declare interface Base {
  a: string
}

declare interface Complex {
  field: Base&{b: number};
}

Typescript code:

const complex: Complex = {
  field: {b: 3, a: 'hello'}
}

Generated externs:

/**
 * @externs
 * @suppress {duplicate,checkTypes}
 */
// NOTE: generated by tsickle, do not edit.
/**
 * @record
 * @struct
 */
function Base() {}
/** @type {string} */
Base.prototype.a;
/**
 * @record
 * @struct
 */
function Complex() {}
/** @type {?} */
Complex.prototype.field;

Closure output:

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/** @type {!Complex} */
const complex = {
    field: { b: 3, a: 'hello' }
};

Compiled code (with rename-properties & generate-pseudo-names):

'use strict';
/**
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode}
 */
const complex = {field:{$b$:3, a:"hello"}};

As you can see, the field param for the type Complex is defined as {?} which causes the field b to never appear in the extern. This causes Closure compiler to rename it in the resulting code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions