@@ -373,6 +373,8 @@ export function nameWithProperty(name: string, lo: { property?: string }): strin
373
373
* @param {Layout } layout - the {@link Layout} instance used to encode
374
374
* instances of `Class`.
375
375
*/
376
+ // `Class` must be a constructor Function, but the assignment of a `layout_` property to it makes it difficult to type
377
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
376
378
export function bindConstructorLayout < T > ( Class : any , layout : Layout < T > ) : void {
377
379
if ( 'function' !== typeof Class ) {
378
380
throw new TypeError ( 'Class must be constructor' ) ;
@@ -1424,6 +1426,8 @@ export class UnionLayoutDiscriminator extends UnionDiscriminator<number> {
1424
1426
* @augments {Layout }
1425
1427
*/
1426
1428
export class Union extends Layout < LayoutObject > {
1429
+ // `property` is assigned in the Layout constructor
1430
+ // @ts -ignore
1427
1431
property : string ;
1428
1432
discriminator : UnionDiscriminator ;
1429
1433
usesPrefixDiscriminator : boolean ;
@@ -1644,6 +1648,8 @@ export class Union extends Layout<LayoutObject> {
1644
1648
}
1645
1649
dest = this . makeDestinationObject ( ) ;
1646
1650
dest [ dlo . property ] = discr ;
1651
+ // defaultLayout.property can be undefined, but this is allowed by buffer-layout
1652
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1647
1653
dest [ defaultLayout ! . property ! ] = defaultLayout ! . decode ( b , offset + contentOffset ) ;
1648
1654
} else {
1649
1655
dest = clo . decode ( b , offset ) ;
@@ -1662,13 +1668,15 @@ export class Union extends Layout<LayoutObject> {
1662
1668
if ( undefined === vlo ) {
1663
1669
const dlo = this . discriminator ;
1664
1670
// this.defaultLayout is not undefined when vlo is undefined
1671
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1665
1672
const clo = this . defaultLayout ! ;
1666
1673
let contentOffset = 0 ;
1667
1674
if ( this . usesPrefixDiscriminator ) {
1668
1675
contentOffset = ( dlo as UnionLayoutDiscriminator ) . layout . span ;
1669
1676
}
1670
1677
dlo . encode ( src [ dlo . property ] , b , offset ) ;
1671
1678
// clo.property is not undefined when vlo is undefined
1679
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1672
1680
return contentOffset + clo . encode ( src [ clo . property ! ] , b , offset + contentOffset ) ;
1673
1681
}
1674
1682
return vlo . encode ( src , b , offset ) ;
@@ -1748,6 +1756,8 @@ export class Union extends Layout<LayoutObject> {
1748
1756
* @augments {Layout }
1749
1757
*/
1750
1758
export class VariantLayout extends Layout < LayoutObject > {
1759
+ // `property` is assigned in the Layout constructor
1760
+ // @ts -ignore
1751
1761
property : string ;
1752
1762
union : Union ;
1753
1763
variant : number ;
@@ -2029,10 +2039,10 @@ export class BitStructure extends Layout<LayoutObject> {
2029
2039
* Layout#property|property}.
2030
2040
*
2031
2041
* @return {Boolean } */
2042
+ // `Boolean` conflicts with the native primitive type
2032
2043
// eslint-disable-next-line @typescript-eslint/ban-types
2033
2044
addBoolean ( property : string ) : Boolean {
2034
2045
// This is my Boolean, not the Javascript one.
2035
- // eslint-disable-next-line no-new-wrappers
2036
2046
const bf = new Boolean ( this , property ) ;
2037
2047
this . fields . push ( bf ) ;
2038
2048
return bf ;
0 commit comments