
* feat(platform-declarations): generate typings from iOS 13.0 SDK * fix(platform-declarations): typings generation script Delete Material Components typings from `tns-platform-declarations`, they are part of `tns-core-modules` package. * refactor(platform-declarations): workaround a TypeScript error Error: ``` tns-platform-declarations/ios/objc-x86_64/objc!OSLog.d.ts(178,15): error TS2417: Class static side 'typeof OSLogEnumerator' incorrectly extends base class static side 'typeof NSEnumerator'. Types of property 'alloc' are incompatible. Type '() => OSLogEnumerator' is not assignable to type '<ObjectType>() => NSEnumerator<ObjectType>'. Type 'OSLogEnumerator' is not assignable to type 'NSEnumerator<ObjectType>'. Types of property 'allObjects' are incompatible. Type 'NSArray<NSObject>' is not assignable to type 'NSArray<ObjectType>'. Type 'NSObject' is not assignable to type 'ObjectType'. 'NSObject' is assignable to the constraint of type 'ObjectType', but 'ObjectType' could be instantiated with a different subtype of constraint '{}'. ``` References: https://github.com/Microsoft/TypeScript/issues/17575 https://stackoverflow.com/questions/52518125/workaround-for-accessing-class-type-arguments-in-static-method-in-typescript * docs(platform-declarations): note a manual step on generating typings * chore(platform-declarations): exclude ios-typings-prj from transpilation * refactor(platform-declarations): delete references to MDC types ``` ios/objc-x86_64/objc!QuartzCore.d.ts:676:36 - error TS2304: Cannot find name 'MDCAnimationTimingFunction'. 676 static mdc_functionWithType(type: MDCAnimationTimingFunction): CAMediaTimingFunction; ios/objc-x86_64/objc!UIKit.d.ts:7717:54 - error TS2304: Cannot find name 'MDCFontTextStyle'. 7717 static mdc_preferredFontForMaterialTextStyle(style: MDCFontTextStyle): UIFont; ios/objc-x86_64/objc!UIKit.d.ts:7719:53 - error TS2304: Cannot find name 'MDCFontTextStyle'. 7719 static mdc_standardFontForMaterialTextStyle(style: MDCFontTextStyle): UIFont; ios/objc-x86_64/objc!UIKit.d.ts:7771:63 - error TS2304: Cannot find name 'MDCFontTextStyle'. 7771 mdc_fontSizedForMaterialTextStyleScaledForDynamicType(style: MDCFontTextStyle, scaled: boolean): UIFont; ios/objc-x86_64/objc!UIKit.d.ts:7794:64 - error TS2304: Cannot find name 'MDCFontTextStyle'. 7794 static mdc_preferredFontDescriptorForMaterialTextStyle(style: MDCFontTextStyle): UIFontDescriptor; ios/objc-x86_64/objc!UIKit.d.ts:7796:63 - error TS2304: Cannot find name 'MDCFontTextStyle'. 7796 static mdc_standardFontDescriptorForMaterialTextStyle(style: MDCFontTextStyle): UIFontDescriptor; ```
This plugin contains type information about the native platforms as exposed by the NativeScript framework.
Offically supported entry points:
android.d.ts
- For android SDK and runtime types.ios.d.ts
- For iOS SDK and runtime types.
Using the declarations may conflict with DOM typings,
consider using TypeScript 2.x.x and the following settings in your tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"lib": [
"es6",
"dom"
]
}
}
Create reference.d.ts
and add the following content:
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
By default the android.d.ts file contains the typings for android API level 17. If your application has a higher minimum API level you can reference that level instead:
/// <reference path="./node_modules/tns-platform-declarations/android-24.d.ts" />
d.ts files require a lot of memory and CPU. Consider adding skipLibCheck option to tsconfig file.
Generate android .d.ts files
- To generate android dependencies use android-dts-generator with the appropriate android version and android support jars
- To regenerate android-*.d.ts file use the android-dts-generator passing the corresponding android jar (described here)
- More details for using the android-dts-generator can be found in this article.
Generate ios .d.ts files
The .d.ts
files for iOS are generated using iOS Runtime's metadata generator. You can use the typings-gen.sh script like this:
./typings-gen.sh rc [<path-to-medatadata-generator-binary>]
Where rc
can be an NPM tag/version of tns-ios
that will be used for generating the typings. If the metadata generator to be used has not been released in NPM, you can optionally specify its path as a 2nd argument.
Note: Apply this commit on hand, due to a TypeScript error.
The script expressly deletes the
objc!MaterialComponents.d.ts
file which distributes along with thetns-core-modules
package to avoid plugins clashes.
However, the metadata generator for iOS includes metadata and typings for the whole SDK and all native libraries in use, including
MaterialComponents
. Therefore, there are typings which reference types fromobjc!MaterialComponents.d.ts
file and fail on transpilation.
Currently, remove these by hand to avoid transpilation errors. A proposed Solution is to specify which entries to be generated metadata for and be accessible from JavaScript. These are the feature requests for Android and iOS