GithubHelp home page GithubHelp logo

kotlin / ts2kt Goto Github PK

View Code? Open in Web Editor NEW
317.0 36.0 26.0 7.91 MB

ts2kt is officially deprecated, please use https://github.com/Kotlin/dukat instead. // Converter of TypeScript definition files to Kotlin external declarations

License: Apache License 2.0

Kotlin 99.45% JavaScript 0.55%
kotlin kotlin-js external-declarations converter typescript kotlin-declarations

ts2kt's Introduction

ts2kt's People

Contributors

abreslav avatar bashor avatar dzharkov avatar epabst avatar erokhins avatar ilya-g avatar schahen avatar shabunc avatar skuzmich avatar udalov avatar yole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ts2kt's Issues

NotImplementedError while converting node mappings

Running ts2kt DefinitelyTyped/types/node/v8/index.d.ts -d headers gives me this error:

ts2kt version: 0.1.0
Converting DefinitelyTyped/types/node/v8/index.d.ts
ts2kt: "StringLiteral" kind unsupported yet here! (DefinitelyTyped/types/node/v8/index.d.ts:125:27 to 126:10)
ts2kt: "StringLiteral" kind unsupported yet here! (DefinitelyTyped/types/node/v8/index.d.ts:126:53 to 127:12)
ts2kt: "StringLiteral" kind unsupported yet here! (DefinitelyTyped/types/node/v8/index.d.ts:127:55 to 128:12)

/usr/lib/node_modules/ts2kt/ts2kt.js:1698
    throw new NotImplementedError_init();
    ^
NotImplementedError: An operation is not implemented.
    at TsClassToKt.Visitor.visitConstructSignatureDeclaration_cz84f8$ (/usr/lib/node_modules/ts2kt/ts2kt.js:1698:11)
    at visitNode (/usr/lib/node_modules/ts2kt/ts2kt.js:2272:15)
    at /usr/lib/node_modules/ts2kt/ts2kt.js:2233:7
    at visitNodes (/usr/lib/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:12699:30)
    at forEachChild (/usr/lib/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:12792:24)
    at forEachChild_0 (/usr/lib/node_modules/ts2kt/ts2kt.js:2238:5)
    at TypeScriptToKotlin.tryTranslateTypeLiteralAsObject_0 (/usr/lib/node_modules/ts2kt/ts2kt.js:3154:5)
    at TypeScriptToKotlin.visitVariableStatement_x0poxd$ (/usr/lib/node_modules/ts2kt/ts2kt.js:3141:29)
    at visitNode (/usr/lib/node_modules/ts2kt/ts2kt.js:2251:15)
    at /usr/lib/node_modules/ts2kt/ts2kt.js:2233:7

The last version it doesn't crash is 0.0.18

FirstType is not supported

e.g. declare function isValidElement<P>(object: {}): object is ReactElement<P>;
This is making the tool fail for react.js.

Better union support

Currently type unions in return types get converted to "dynamic". This is pretty unsafe. I'm proposing a safer method, with some Kotlin code attached.
Given a function that returns string|number, generate:

external fun someFunction() : StringOrNumber;
external class StringOrNumber
inline fun <T> StringOrNumber.destructure(
		onString : (String)->T,
		onNumber: (Number)->T
) : T{
	if("string".equals(jsTypeOf(this))){
		return onString(this.unsafeCast<String>())
	} else if("number".equals(jsTypeOf(this))){
		return onNumber(this.unsafeCast<Number>())
	} else {
		throw IllegalStateException("Value is neither type 'string' nor type 'number': ${this}")
	}
}

The inline function would have to be generated in a separate Kotlin file, but it could make for safer code, which might improve the quality of the converter itself. We'd need a type discriminant per type, however. Some libraries define their own type discriminants, but following a basic primitive type/known disjoint properties method could be helpful, especially with string literal types.
I can try to generate a proof of concept implementation if this seems okay.

Let's improve ts2kt together!

Hi, @bashor!

I am new to Kotlin and I like it a lot! I am also interesting in contribution to ts2kt.

It's difficult for me now to understand ERs (Expected Result) for existing issues.

So, may you have any small tasks for community?

Have a nice day! ๐Ÿ™‚

Generated extension functions don't compile

Example:

/// <reference path="../../testDefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts" />

interface JQuery {
    foo()
    bar
    [prop: string]: number;
    someField: string;
    optionalField?: any;
    (resourceId:string, hash?:any, callback?:Function): void;
}

results in:

external fun JQuery.foo(): Unit = definedExternally
external var JQuery.bar: Any get() = definedExternally; set(value) = definedExternally
@nativeGetter
external operator fun JQuery.get(prop: String): Number? = definedExternally
@nativeSetter
external operator fun JQuery.set(prop: String, value: Number): Unit = definedExternally
external var JQuery.someField: String get() = definedExternally; set(value) = definedExternally
external var JQuery.optionalField: Any? get() = definedExternally; set(value) = definedExternally
@nativeInvoke
external operator fun JQuery.invoke(resourceId: String, hash: Any? = definedExternally /* null */, callback: Function<*>? = definedExternally /* null */): Unit = definedExternally

which fails with compile error "Declaration of such kind (extension function) cant be external", etc.
It should be:

fun JQuery.foo(): Unit { this.asDynamic().foo() }
var JQuery.bar: Any get() = this.asDynamic().bar; set(value) { this.asDynamic().bar = value }
operator fun JQuery.get(prop: String): Number? { return this.asDynamic().get(prop) }
operator fun JQuery.set(prop: String, value: Number): Unit { this.asDynamic().set(prop, value) }
var JQuery.someField: String get() = this.asDynamic().someField; set(value) { this.asDynamic().someField = value }
var JQuery.optionalField: Any? get() = this.asDynamic().optionalField; set(value) { this.asDynamic().optionalField = value }
operator fun JQuery.invoke(resourceId: String, hash: Any? = null, callback: Function<*>? = null): Unit { this.asDynamic().invoke(resourceId, hash, callback) }

Switch to gradle build

Pros:

  • Incremental compilation
  • Dogfooding (gradle integration, and IC)

Cons:

  • Slow run/configuarion

Unclear how to run tool

I followed the steps in the README, but I still don't have .kt files for rx. How do I run this tool to actually convert ts to kt? Please add these steps to the README.

Throws exception when converting lodash

Program doesn't even terminate with lodash:

$(npm bin)/ts2kt -d headers node_modules/@types/lodash/index.d.ts
Converting node_modules/@types/lodash/index.d.ts
ts2kt: "NamespaceExportDeclaration" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:238:12 to 239:23)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:2079:23 to 2079:49)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:7286:22 to 7286:36)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:7338:22 to 7338:36)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:7373:22 to 7373:36)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:7415:22 to 7415:36)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:7450:22 to 7450:36)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:9337:32 to 9337:45)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:9345:32 to 9345:45)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:9385:32 to 9385:45)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:9408:32 to 9408:45)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:9431:32 to 9431:45)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/lodash/index.d.ts:9454:32 to 9454:45)
/home/max/IdeaProjects/kiq/node_modules/typescript/lib/typescript.js:5738
        return identifier.length >= 3 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ && identifier.charCodeAt(2) === 95 /* _ */ ? identifier.substr(1) : identifier;
                         ^

TypeError: Cannot read property 'length' of undefined
    at Object.unescapeIdentifier (/home/max/IdeaProjects/kiq/node_modules/typescript/lib/typescript.js:5738:26)
    at TsInterfaceToKt.TsClassifierToKt.visitPropertyDeclaration_qnxew1$ (/home/max/IdeaProjects/kiq/node_modules/ts2kt/ts2kt.js:952:35)
    at visitNode (/home/max/IdeaProjects/kiq/node_modules/ts2kt/ts2kt.js:3942:15)
    at /home/max/IdeaProjects/kiq/node_modules/ts2kt/ts2kt.js:3897:7
    at visitEachNode (/home/max/IdeaProjects/kiq/node_modules/typescript/lib/typescript.js:8343:30)
    at Object.forEachChild (/home/max/IdeaProjects/kiq/node_modules/typescript/lib/typescript.js:8429:24)
    at forEachChild_0 (/home/max/IdeaProjects/kiq/node_modules/ts2kt/ts2kt.js:3901:24)
    at ObjectTypeToKotlinTypeMapperImpl.getKotlinTypeForObjectType_29gnwt$ (/home/max/IdeaProjects/kiq/node_modules/ts2kt/ts2kt.js:438:5)
    at toKotlinType_3 (/home/max/IdeaProjects/kiq/node_modules/ts2kt/ts2kt.js:3666:23)
    at toKotlinType_0 (/home/max/IdeaProjects/kiq/node_modules/ts2kt/ts2kt.js:3718:16)
/home/max/IdeaProjects/kiq
โ”œโ”€โ”€ @types/[email protected]
โ”œโ”€โ”€ @types/[email protected]
โ”œโ”€โ”€ @types/[email protected]
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”€ [email protected]

Error: "External class constructor cannot have a property parameter"

Example

declare class BarWithProperty {
    constructor(public n: number, public a);
}

is resulting in:

external open class BarWithProperty(open var n: Number, open var a: Any)

which has compile error "External class constructor cannot have a property parameter".

This fixes that error:

external open class BarWithProperty(n: Number, a: Any) {
    open var n: Number
    open var a: Any
}

README run with node.js instruction is wrong

Running node build/distrib/ts2kt.js path/to/input.d.ts path/to/output.kt results in

ts2kt supports to convert only TypeScript definition files (d.ts)

Debugging the script showed that also path/to/input.d.ts path/to/output.kt was interpreted as a source, because it doesn't starts with '-'.

Adding '-d' works perfectly.

Cannot convert "material-ui" package

I'm trying to convert "material-ui" package which is located here: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/material-ui
I tried 0.18.5 version: npm i @types/[email protected]

I use "ts2kt-automator" wrapper (but it just runs ts2kt by CLI command shown above)

But ts2kt fails with following output:

Running command:  /Users/***/Documents/github/create-react-kotlin-app/node_modules/ts2kt/ts2kt.js -d test/build/material-ui /Users/***/Documents/github/create-react-kotlin-app/packages/ts2kt-automator/node_modules/@types/material-ui/index.d.ts
ts2kt version: 0.0.16
Converting /Users/***/Documents/github/create-react-kotlin-app/packages/ts2kt-automator/node_modules/@types/material-ui/index.d.ts
Save declarations:
        test/build/material-ui/index.kt
        test/build/material-ui/index.__MaterialUI.kt
        test/build/material-ui/index.__MaterialUI.Styles.kt
        test/build/material-ui/index.__MaterialUI.propTypes.kt
        test/build/material-ui/index.__MaterialUI.BottomNavigation.kt
        test/build/material-ui/index.__MaterialUI.Card.kt
        test/build/material-ui/index.__MaterialUI.DatePicker.kt
        test/build/material-ui/index.__MaterialUI.GridList.kt
        test/build/material-ui/index.__MaterialUI.List.kt
        test/build/material-ui/index.__MaterialUI.Menus.kt
        test/build/material-ui/index.__MaterialUI.Popover.kt
        test/build/material-ui/index.__MaterialUI.Switches.kt
        test/build/material-ui/index.__MaterialUI.Stepper.kt
        test/build/material-ui/index.__MaterialUI.Table.kt
        test/build/material-ui/index.__MaterialUI.Tabs.kt
        test/build/material-ui/index.__MaterialUI.Toolbar.kt
        test/build/material-ui/index.__MaterialUI.Utils.kt
        test/build/material-ui/index.__MaterialUI.Utils.ColorManipulator.kt
        test/build/material-ui/index.material-ui/styles/colors.kt
ts2kt: exportedByAssignment should be empty, but it contains: [Dom, Tab, AvSubtitles, AvHd, Card, Chip, List, Menu, Tabs, ImageCameraRear, ImageCameraRoll, ContentCreate, TableBody, ActionNoteAdd, CommunicationChatBubble, ContentDrafts, CardText, ActionViewArray, AvMic, AvWeb, AvPlaylistAdd, Badge, MapsTraffic, ActionViewQuilt, AvPlayCircleOutline, Paper, Table, MapsAddLocation, EditorMonetizationOn, ActionQueryBuilder, HardwareCastConnected, ImageTimerOff, SocialLocationCity, ImageCameraFront, ImageLooksOne, ImageLooksTwo, SocialCake, SocialMood, SocialPoll, MapsLocalDining, ActionFavorite, MapsLocalLaundryService, ActionImportantDevices, ActionSettingsInputAntenna, HardwarePhoneIphone, NotificationDoNotDisturbAlt, NotificationDoNotDisturbOff, NotificationPhoneInTalk, AvSurroundSound, ActionGroupWork, NotificationSyncDisabled, ActionTheaters, DeviceBluetoothSearching, ImageSwitchVideo, ActionQuestionAnswer, PlacesKitchen, AvSlowMotionVideo, ImageExposure, NotificationPhoneLocked, PopoverAnimationDefault, ActionPermContactCalendar, MapsTram, EditorTextFields, NotificationPhoneMissed, ActionMotorcycle, ActionSettingsInputHdmi, ImageLeakRemove, ActionExitToApp, ActionViewList, ActionViewWeek, NotificationVoiceChat, AvEqualizer, NavigationArrowDropDownCircle, ActionSubject, NavigationExpandLess, NavigationExpandMore, CommunicationImportContacts, MapsDirections, Snackbar, NotificationPhonePaused, NotificationAirlineSeatIndividualSuite, MapsLocalGasStation, ActionSwapHoriz, FileCreateNewFolder, GridList, GridTile, ImageColorLens, ActionVisibilityOff, MapsLocalMovies, AvArtTrack, ActionTrendingUp, HardwarePhonelink, ImageBlurLinear, EditorShortText, FontIcon, ContentRemove, ContentReport, AvHearing, CommunicationCallMissedOutgoing, ActionRoundedCorner, ImageFilterNone, EditorSpaceBar, CommunicationInvertColorsOff, EditorAttachMoney, ActionSupervisorAccount, PlacesFitnessCenter, EditorInsertEmoticon, EditorModeComment, ActionCompareArrows, ActionSettings, SocialMoodBad, TableHeaderColumn, EditorBorderBottom, ImageBrush, Toolbar, EditorShowChart, ImageFlare, NotificationEnhancedEncryption, ImageGrain, ImageHdrOn, ImageImage, ImageLooks, ImageLoupe, ImagePhoto, ActionSettingsBluetooth, ActionPictureInPictureAlt, ImageStyle, ImageTimer, CommunicationPhonelinkErase, CommunicationPhonelinkSetup, ActionCardTravel, MapsPinDrop, CommunicationSwapCalls, MapsDirectionsTransit, ContentWeekend, ActionAlarmAdd, ActionAlarmOff, ToolbarGroup, ActionDashboard, EditorBorderLeft, FlatButton, ToolbarTitle, AvFiberDvr, AvFiberNew, AvFiberPin, ActionCardMembership, EditorWrapText, DeviceSignalCellularConnectedNoInternet0Bar, DeviceSignalCellularConnectedNoInternet1Bar, DeviceSignalCellularConnectedNoInternet2Bar, DeviceSignalCellularConnectedNoInternet3Bar, DeviceSignalCellularConnectedNoInternet4Bar, FileCloud, EditorTitle, NotificationBluetoothAudio, NotificationEventAvailable, AvMicNone, ActionFavoriteBorder, ActionBookmarkBorder, BottomNavigation, ActionSwapVerticalCircle, AvReplay5, NotificationAirlineSeatLegroomExtra, ImageCenterFocusStrong, PlacesSmokeFree, CommunicationStopScreenShare, ImageBlurOff, ActionHelpOutline, AvBrandingWatermark, ImageMovieFilter, NotificationMore, NotificationSync, NotificationWifi, RadioButton, NavigationArrowDownward, AvVideoCall, PlacesChildFriendly, HardwareLaptopMac, CommunicationCallMerge, ContentAddCircle, ImageLeakAdd, CommunicationCallSplit, AvPauseCircleOutline, ActionFlipToBack, MapsDirectionsSubway, NavigationChevronRight, EditorMultilineChart, ActionAccountCircle, AvPlayCircleFilled, HardwareGamepad, ActionThumbUp, CommunicationVoicemail, MapsPersonPin, ActionExplore, ImageBlurCircular, ToggleRadioButtonUnchecked, AvWebAsset, NavigationArrowDropRight, CommunicationEmail, CommunicationForum, ImageBurstMode, NavigationRefresh, ActionAssignment, CommunicationNoSim, CommunicationPhone, ActionOpacity, ImageCropLandscape, TableRowColumn, TextField, ActionSettingsApplications, AvAddToQueue, NavigationMoreHoriz, DeviceAccessTime, PopoverAnimationVertical, ContentBlock, ContentClear, DeviceGraphicEq, ActionReportProblem, ContentInbox, ContentReply, ImageBrightness1, ImageBrightness2, ImageBrightness3, ImageBrightness4, ImageBrightness5, ImageBrightness6, ImageBrightness7, ActionLockOpen, ContentReplyAll, AvAlbum, AvGames, ActionSettingsRemote, IconButton, AvMovie, AvPause, AvQueue, AvRadio, AlertAddAlert, DeviceWidgets, MapsLocalShipping, ContentRemoveCircle, NotificationTimeToLeave, ActionExtension, ImageGridOff, AvQueuePlayNext, HardwarePhonelinkOff, EditorFormatAlignJustify, CardActions, ImageRotate90DegreesCcw, ActionCheckCircle, ActionBookmark, HardwareMouse, ImageViewComfy, FloatingActionButton, HardwareWatch, ActionChromeReaderMode, EditorInsertChart, ActionLabelOutline, ActionRestorePage, EditorInsertPhoto, EditorAttachFile, ActionShoppingCart, ImageCrop, ImageEdit, ImageFlip, ImageLens, ImageTune, ImageFilterVintage, ToggleStar, ImageTonality, ActionAllOut, HardwareLaptopChromebook, SocialWhatshot, ContentDeleteSweep, ActionBackup, DeviceBrightnessAuto, DeviceBrightnessHigh, ContentContentCut, ContentRemoveCircleOutline, ActionCached, ActionRemoveShoppingCart, AvReplay10, AvReplay30, NotificationVibration, NotificationAirlineSeatFlat, ImageSwitchCamera, AvFastForward, ActionDelete, CommunicationStayPrimaryLandscape, MapsLocalHospital, ActionDonutLarge, DeviceDevices, ActionDonutSmall, ContentMoveToInbox, EditorFormatItalic, ActionAlarmOn, CommunicationBusiness, AvMicOff, Popover, EditorFormatLineSpacing, ActionTrackChanges, ActionVerifiedUser, ContentFlag, ContentLink, ContentMail, ContentRedo, ContentSave, ContentSend, ContentSort, ContentUndo, LinearProgress, ActionDeleteForever, ActionViewHeadline, PlacesRoomService, ActionTimeline, ActionGetApp, CommunicationCallReceived, ActionAndroid, PlacesBusinessCenter, NotificationEventBusy, NotificationEventNote, EditorDragHandle, DeviceSignalCellular0Bar, DeviceSignalCellular1Bar, DeviceSignalCellular2Bar, DeviceSignalCellular3Bar, DeviceSignalCellular4Bar, DeviceSignalCellularNull, PlacesAcUnit, ImageTagFaces, ActionPanTool, MapsLocalDrink, MapsLocalHotel, DeviceSignalWifi3BarLock, MapsEvStation, ActionDateRange, MapsLocalOffer, ActionPayment, MapsLocalPhone, MapsLocalPizza, AvRepeat, AvReplay, ListItem, MapsLocalAirport, EditorVerticalAlignBottom, AvVideoLibrary, Typography, PlacesCasino, EditorVerticalAlignCenter, ImageFilter9Plus, ImageWbIridescent, AvSnooze, ActionOpenInBrowser, ImageFilterBAndW, ActionLaunch, ImageFilterDrama, HardwareDeviceHub, DatePickerDialog, ImagePhotoAlbum, EditorInsertComment, NotificationAirlineSeatLegroomNormal, NotificationAirlineSeatReclineNormal, MapsLocalPostOffice, MapsTransferWithinAStation, EditorFormatShapes, MapsFlight, ImageColorize, DeviceAirplanemodeInactive, ImageCropPortrait, ImageHdrWeak, ImageFlashAuto, AvForward10, AvForward30, TableFooter, ActionSettingsPhone, ActionSettingsPower, ImageHealing, ActionSettingsVoice, NotificationAirlineSeatReclineExtra, ActionPictureInPicture, ActionPermPhoneMsg, PlacesHotTub, NavigationUnfoldLess, NavigationUnfoldMore, Checkbox, TableHeader, RefreshIndicator, ActionAddShoppingCart, MapsLocalParking, AvVolumeOff, ActionRedeem, CommunicationChatBubbleOutline, NotificationNetworkLocked, DeviceSettingsSystemDaydream, DeviceWifiLock, MapsLocalFlorist, ActionRowing, PlacesBeachAccess, DeviceBattery20, DeviceBattery30, DeviceBattery50, DeviceBattery60, DeviceBattery80, DeviceBattery90, BottomNavigationItem, ActionSearch, HardwareComputer, NotificationSmsFailed, ActionEventSeat, HardwareCast, HardwareDock, HardwarePhoneAndroid, MapsLayers, HardwareToys, NavigationLastPage, AvShuffle, ImageCompare, DeviceAddAlarm, ActionOfflinePin, ActionUpdate, ActionSettingsOverscan, DeviceLocationSearching, ActionLightbulbOutline, CardMedia, PlacesPool, CardTitle, ToggleStarHalf, CircularProgress, MapsNearMe, ActionLanguage, HardwareKeyboardTab, ActionAssignmentReturned, DeviceDataUsage, EditorHighlight, CommunicationPortableWifiOff, ToggleIndeterminateCheckBox, DeviceGpsFixed, ImageExposurePlus1, ImageExposurePlus2, ActionPolymer, ImageStraighten, ActionViewAgenda, HardwareKeyboardBackspace, NotificationDriveEtafs.js:652
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'test/build/material-ui/index.material-ui/styles/colors.kt'
    at Object.fs.openSync (fs.js:652:18)
    at Object.fs.writeFileSync (fs.js:1299:33)
    at translateToDir (/Users/***/Documents/github/create-react-kotlin-app/node_modules/ts2kt/ts2kt.js:4582:20)
    at main (/Users/***/Documents/github/create-react-kotlin-app/node_modules/ts2kt/ts2kt.js:4764:5)
    at /Users/***/Documents/github/create-react-kotlin-app/node_modules/ts2kt/ts2kt.js:5588:3
    at Object.<anonymous> (/Users/***/Documents/github/create-react-kotlin-app/node_modules/ts2kt/ts2kt.js:5591:2)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)

Development of the project

I have recently discovered Kotlin and liked it a lot! As for me, it fits Javascript better than Typescript.
Moreover, Kotlin provides a modern and top-notch OOP, including operator overloading. (Oh, I missed so much arbitrary types as keys in Map because no hashCode() introduced).

Kotlin provides a modern framework and excellent type safety. But the fact is that TS has already become a de-facto standard. So, existing libraries must be converted into Kotlin otherwise it will make not much sense (phew, defining every lib as dynamic).

The question is: will the project be further developed?
Things, that are missing are:

  • adequate package name resolution using @JsModule, e.g. moment.js Kotlin files don't add it, so moment is not imported in transpiled code. It can be done by providing another cli argument;
  • automatic resolving of all dependencies. If only output dir supplied, then use pwd and app-root-path module to define app root, checkout package.json, search for every package in ./node_modules/@types/, convert if absent, search for ./node_modules/ (some modules include it with js code) and convert if also absent. While converting, resolve every import statement like described above;
  • fix minor issues, listed in issues and some other (e.g. it appends override to valueOf method, but there is not in Any type).

P.S. I initially forked it to do develop it, but I realised that it is to tough to do along considering my poor knowledge of both Kotlin and tsc API.
If someone supports the idea or already developing in a fork I am eager to take part

override modifier should be added even if return types don't match

Kotlin, Java, etc. don't allow methods to return incompatible return types
because the uniqueness of a method doesn't include the return type.
This was causing a compilation error for reactive.d.ts.
If for reason they are incompatible, ts2kt should leave that for the compiler to deal with
rather than guarantee a compilation error by omitting the override modifier.

TypeError happens when converting some d.ts files.

TypeError happens at typescript.js when I'm trying to convert some d.ts files.

Converting node_modules/@types/whatwg-fetch/index.d.ts
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/@types/whatwg-fetch/index.d.ts:11:19 to 11:39)
ts2kt: "TupleType" kind unsupported yet here! (node_modules/@types/whatwg-fetch/index.d.ts:24:33 to 24:49)
/usr/local/lib/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:5738
        return identifier.length >= 3 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ && identifier.charCodeAt(2) === 95 /* _ */ ? identifier.substr(1) : identifier;
                         ^

TypeError: Cannot read property 'length' of undefined
    at Object.unescapeIdentifier (/usr/local/lib/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:5738:26)
    at TsClassToKt.TsClassifierToKt.visitMethodDeclaration_7vsj57$ (/usr/local/lib/node_modules/ts2kt/ts2kt.js:969:35)
    at visitNode (/usr/local/lib/node_modules/ts2kt/ts2kt.js:3939:15)
    at TsClassToKt.visitClassDeclaration_4wvyue$ (/usr/local/lib/node_modules/ts2kt/ts2kt.js:1024:7)
    at TypeScriptToKotlin.visitClassDeclaration_4wvyue$ (/usr/local/lib/node_modules/ts2kt/ts2kt.js:1393:16)
    at visitNode (/usr/local/lib/node_modules/ts2kt/ts2kt.js:3921:15)
    at /usr/local/lib/node_modules/ts2kt/ts2kt.js:3897:7
    at visitEachNode (/usr/local/lib/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:8343:30)
    at Object.forEachChild (/usr/local/lib/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:8503:24)
    at forEachChild_0 (/usr/local/lib/node_modules/ts2kt/ts2kt.js:3901:24)

Environment

  • npm 4.4.0
  • typescript 2.2.1
  • ts2kt 0.0.12

Reproduce script

npm init -f
npm install --save whatwg-fetch
npm install --save @types/whatwg-fetch
ts2kt -d dist node_modules/\@types/whatwg-fetch/index.d.ts

`"<file path>".Foo` shows up when referencing exported type

Example:

export type StructureType = {
    name: string;
    details?: string;
};
export interface Registry {
    register(type: StructureType)
}

ends up including:

external interface Registry {
    fun register(type: `"testData/objectType/useExportedType".StructureType`)
}

but should just have:

external interface Registry {
    fun register(type: StructureType)
}

Cannot convert react.d.ts

I'm trying to convert the React type declaration file, but am coming across some errors.

I run

$ node_modules/.bin/ts2kt -d headers node_modules/@types/react/index.d.ts

But this gets output:

Converting node_modules/@types/react/index.d.ts
ts2kt: "NamespaceExportDeclaration" kind unsupported yet here! (node_modules/@types/react/index.d.ts:7:16 to 8:27)
/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:5738
        return identifier.length >= 3 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ && identifier.charCodeAt(2) === 95 /* _ */ ? identifier.substr(1) : identifier;
                         ^

TypeError: Cannot read property 'length' of undefined
    at Object.unescapeIdentifier (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:5738:26)
    at TsInterfaceToKt.TsClassifierToKt.visitPropertyDeclaration_qnxew1$ (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/ts2kt.js:952:35)
    at visitNode (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/ts2kt.js:3942:15)
    at /Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/ts2kt.js:3897:7
    at visitEachNode (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:8343:30)
    at Object.forEachChild (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/node_modules/typescript/lib/typescript.js:8429:24)
    at forEachChild_0 (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/ts2kt.js:3901:24)
    at ObjectTypeToKotlinTypeMapperImpl.getKotlinTypeForObjectType_29gnwt$ (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/ts2kt.js:438:5)
    at toKotlinType_3 (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/ts2kt.js:3666:23)
    at toKotlinType_0 (/Users/kengorab/code/kotlinjs-test/node_modules/ts2kt/ts2kt.js:3718:16)

I'm using [email protected] in my project's dependencies, but I noticed the ts2kt project depends on [email protected]; I don't know if that's related, but I figured I'd mention that the tool is using an outdated version, and some type definitions which get updated frequently (React being one of them) might not work with older versions.

Switch to generated tests

Pros:

  • More convenient running part of tests
  • Dogfooding for unit testing
    Cons:
  • Must regenerate every time after adding new tests
  • Minor [1]: No navigation to testdata

[1] Minor since it will not be lost with this change, it's just unsupported for Kotlin tests

Deprecate and direct users to Dukat

These tools both seem like they do the same thing, and Dukat is being integrated into the official gradle plugin.

I propose deprecating this and directing users to Dukat.

Cannot convert react-redux

When trying to convert the react-redux typescript definitions to kotlin the following exception ocurrs:

cd DefinatelyTyped/types/react-redux
ts2kt index.d.ts

ts2kt version: 0.0.14
Converting index.d.ts
ts2kt: "ImportDeclaration" kind unsupported yet here! (index.d.ts:1:1 to 13:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (index.d.ts:13:32 to 14:32)
ts2kt: "ComputedPropertyName" kind unsupported yet here! (index.d.ts:25:51 to 25:60)
ts2kt: "ComputedPropertyName" kind unsupported yet here! (index.d.ts:25:69 to 25:78)
ts2kt: "NeverKeyword" kind unsupported yet here! (index.d.ts:25:104 to 25:110)
ts2kt: "NeverKeyword" kind unsupported yet here! (index.d.ts:25:104 to 25:110)
ts2kt: "ExpressionStatement" kind unsupported yet here! (index.d.ts:25:114 to 25:115)
ts2kt: "EmptyStatement" kind unsupported yet here! (index.d.ts:25:116 to 25:117)
ts2kt: "ExpressionStatement" kind unsupported yet here! (index.d.ts:26:53 to 26:61)
/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:30833
  function DelimitedRangesSequence$iterator$ObjectLiteral(this$DelimitedRangesSequence) {
                                                         ^

RangeError: Maximum call stack size exceeded
    at new DelimitedRangesSequence$iterator$ObjectLiteral (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:30833:58)
    at DelimitedRangesSequence.iterator (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:30886:12)
    at new TransformingSequence$iterator$ObjectLiteral (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:28035:58)
    at TransformingSequence.iterator (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:28045:12)
    at toCollection_9 (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:19264:22)
    at toMutableList_10 (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:19278:12)
    at toList_10 (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:19275:33)
    at lines (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:31006:12)
    at replaceIndent (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:29495:19)
    at trimIndent (/usr/local/share/.config/yarn/global/node_modules/ts2kt/kotlin.js:29488:12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.