File tree Expand file tree Collapse file tree 5 files changed +68
-6
lines changed Expand file tree Collapse file tree 5 files changed +68
-6
lines changed Original file line number Diff line number Diff line change @@ -824,13 +824,20 @@ export class ApiModelGenerator {
824
824
const nodesToCapture : IExcerptBuilderNodeToCapture [ ] = [ ] ;
825
825
826
826
const propertyTypeTokenRange : IExcerptTokenRange = ExcerptBuilder . createEmptyTokenRange ( ) ;
827
+ let propertyTypeNode : ts . TypeNode | undefined ;
828
+
829
+ if (
830
+ ts . isPropertyDeclaration ( astDeclaration . declaration ) ||
831
+ ts . isGetAccessorDeclaration ( astDeclaration . declaration )
832
+ ) {
833
+ propertyTypeNode = astDeclaration . declaration . type ;
834
+ }
835
+
836
+ if ( ts . isSetAccessorDeclaration ( astDeclaration . declaration ) ) {
837
+ // Note that TypeScript always reports an error if a setter does not have exactly one parameter.
838
+ propertyTypeNode = astDeclaration . declaration . parameters [ 0 ] . type ;
839
+ }
827
840
828
- // If the property declaration's type is `undefined`, then we're processing a setter with no corresponding
829
- // getter. Use the parameter type instead (note that TypeScript always reports an error if a setter
830
- // does not have exactly one parameter).
831
- const propertyTypeNode : ts . TypeNode | undefined =
832
- ( astDeclaration . declaration as ts . PropertyDeclaration | ts . GetAccessorDeclaration ) . type ||
833
- ( astDeclaration . declaration as ts . SetAccessorDeclaration ) . parameters [ 0 ] . type ;
834
841
nodesToCapture . push ( { node : propertyTypeNode , tokenRange : propertyTypeTokenRange } ) ;
835
842
836
843
const excerptTokens : IExcerptToken [ ] = this . _buildExcerptTokens ( astDeclaration , nodesToCapture ) ;
Original file line number Diff line number Diff line change 685
685
},
686
686
"isStatic" : false
687
687
},
688
+ {
689
+ "kind" : " Property" ,
690
+ "canonicalReference" : " api-extractor-scenarios!SimpleClass#someReadonlyProp:member" ,
691
+ "docComment" : " " ,
692
+ "excerptTokens" : [
693
+ {
694
+ "kind" : " Content" ,
695
+ "text" : " readonly someReadonlyProp = 5;"
696
+ }
697
+ ],
698
+ "isOptional" : false ,
699
+ "releaseTag" : " Public" ,
700
+ "name" : " someReadonlyProp" ,
701
+ "propertyTypeTokenRange" : {
702
+ "startIndex" : 0 ,
703
+ "endIndex" : 0
704
+ },
705
+ "isStatic" : false
706
+ },
707
+ {
708
+ "kind" : " Property" ,
709
+ "canonicalReference" : " api-extractor-scenarios!SimpleClass#someReadonlyPropWithType:member" ,
710
+ "docComment" : " " ,
711
+ "excerptTokens" : [
712
+ {
713
+ "kind" : " Content" ,
714
+ "text" : " readonly someReadonlyPropWithType: "
715
+ },
716
+ {
717
+ "kind" : " Content" ,
718
+ "text" : " number"
719
+ },
720
+ {
721
+ "kind" : " Content" ,
722
+ "text" : " ;"
723
+ }
724
+ ],
725
+ "isOptional" : false ,
726
+ "releaseTag" : " Public" ,
727
+ "name" : " someReadonlyPropWithType" ,
728
+ "propertyTypeTokenRange" : {
729
+ "startIndex" : 1 ,
730
+ "endIndex" : 2
731
+ },
732
+ "isStatic" : false
733
+ },
688
734
{
689
735
"kind" : " Property" ,
690
736
"canonicalReference" : " api-extractor-scenarios!SimpleClass#writeableProperty:member" ,
Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ export class SimpleClass {
62
62
// (undocumented)
63
63
get readonlyProperty(): string ;
64
64
// (undocumented)
65
+ readonly someReadonlyProp = 5 ;
66
+ // (undocumented)
67
+ readonly someReadonlyPropWithType: number ;
68
+ // (undocumented)
65
69
get writeableProperty(): string ;
66
70
set writeableProperty(value : string );
67
71
}
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ export declare class SimpleClass {
58
58
get readonlyProperty ( ) : string ;
59
59
get writeableProperty ( ) : string ;
60
60
set writeableProperty ( value : string ) ;
61
+ readonly someReadonlyProp = 5 ;
62
+ readonly someReadonlyPropWithType : number ;
61
63
}
62
64
63
65
/** @public */
Original file line number Diff line number Diff line change @@ -20,4 +20,7 @@ export class SimpleClass {
20
20
return 'hello' ;
21
21
}
22
22
public set writeableProperty ( value : string ) { }
23
+
24
+ readonly someReadonlyProp = 5 ;
25
+ readonly someReadonlyPropWithType : number = 5 ;
23
26
}
You can’t perform that action at this time.
0 commit comments