react-native-* .js导入* .ts文件

时间:2018-07-07 04:55:34

标签: javascript typescript react-native

如何允许let nota = prompt("Ingrese su nota: "); if (nota >= 90){ console.log(nota + " " + "equivale a una A"); } else if (nota == 80 || nota <= 89){ console.log(nota + " " + "equivale a una B"); } else if (nota == 70 || nota <= 79){ console.log(nota + " " + "equivale a una C"); } else if (nota == 60 || nota <= 69){ console.log(nota + " " + "equivale a una D"); } else{ console.log("Tienes una F"); } 文件导入*.js中的*.ts文件,但不重命名两个文件中的任何一个

我们要从react-native .js

导入src/lib/setGlobalStyle .ts 文件以下
src/App

但在//MIT LICENSE from: https://github.com/Ajackster/react-native-global-props import React from 'react' import { StyleProp, ViewStyle } from 'react-native' export function setGlobalStyle(obj, customProps) { const oldRender = obj.prototype.render; const initialDefaultProps = obj.prototype.constructor.defaultProps; obj.prototype.constructor.defaultProps = { ...initialDefaultProps, ...customProps, } obj.prototype.render = function render() { let oldProps = this.props; this.props = { ...this.props, style: [customProps.style, this.props.style] }; try { return oldRender.apply(this, arguments); } finally { this.props = oldProps; } }; } .js 内部的导入下面,仅当我们将App .ts 文件重命名为setGlobalStyle时有效 .js

setGlobalStyle

,当然import * as Utils from './lib/setGlobalStyle' .ts 当前不包含任何setGlobalStyle类型,这是因为我们必须删除所有类型并将其重命名为 .js ,因此我们可以继续进行该项目,直到获得答案为止。

注释:我们需要TypeScript的原因是允许TypeScript自动完成参数(即IDE参数)。

1 个答案:

答案 0 :(得分:1)

JSDoc-support in Javascript允许您直接导入类型定义。我知道这与导入实际模块不同(但是如果类型定义存在,我认为那很疯狂):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xpath-default-namespace="http://www.eclipse.org/birt/2005/design"
    xmlns="http://www.eclipse.org/birt/2005/design"
    exclude-result-prefixes="xs"
    expand-text="yes"
    version="3.0">

  <!-- second document inlined for the example,
       use param name="doc2" select="doc('file2.xml')
       instead to load external file -->
  <xsl:param name="doc2" xmlns="">
<model>
    <layouts>
        <layout ID="001" name="PersonTemplate" format="Table" nFields="3" >
            <fields>
                <field name="NameTitle"/>
                <field name="CityTitle"/>
                <field name="AgeTitle"/>
            </fields>
        </layout>
        <layout ID="002" name="SchoolTemplate" format="Table" nFields="3" >
            <fields>
                <field name="NameTitle"/>
                <field name="LocationTitle"/>
                <field name="MaxCapacityTitle"/>
            </fields>
        </layout>
    </layouts>
    <reports>
        <report layoutID="001">
            <params>
                <sources>
                    <source name="source1" dbURL="sampledb1.com" user="user1" password="dXNlcjE=" driver="dbDriver"/>
                    <source name="source2" dbURL="sampledb2.com" user="user2" password="dXNlcjI=" driver="dbDriver"/>
                </sources>
                <set name="set1" source="source1" querie="select Name, City, Age from PeopleTable" >
                    <qFields>
                        <qField name="Name" type="string"/>
                        <qField name="City" type="string"/>
                        <qField name="Age" type="integer"/>
                    </qFields>
                </set>
            </params>
        </report>
        <report layoutID="002">
            <params>
                <sources>
                    <source name="source1" dbURL="sampledb1.com" user="user1" password="dXNlcjE=" driver="dbDriver"/>
                </sources>
                <set name="Data Set" dataSource="source1" querie="select Name, Location, MaxCapacity from SchoolsTable" >
                    <qFields>
                        <qField name="Name" type="string"/>
                        <qField name="Location" type="string"/>
                        <qField name="MaxCapacity" type="integer"/>
                    </qFields>
                </set>
            </params>
        </report>
    </reports>
</model>      
  </xsl:param>

  <xsl:output indent="yes"/>

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:key name="layout-ref" match="layout" use="@name" xpath-default-namespace=""/>
  <xsl:key name="report-ref" match="report" use="@layoutID" xpath-default-namespace=""/>

  <xsl:template match="report/text-prop[@name = 'displayName']">
      <xsl:next-match/>
      <xsl:variable name="layout" select="key('layout-ref', ., $doc2)"/>
      <xsl:variable name="report" select="key('report-ref', $layout/@ID, $doc2)"/>
      <dataSources>
          <xsl:apply-templates select="$report//source" xpath-default-namespace=""/>
      </dataSources>
      <data-sets>
          <xsl:apply-templates select="$report//set" xpath-default-namespace=""/>
      </data-sets>

  </xsl:template>

  <xsl:template match="source" xpath-default-namespace="">
      <data-source extensionID="this.is.a.fixed.value" name="{@name}">
          <xsl:apply-templates select="@* except @name"/>
      </data-source>
  </xsl:template>

  <xsl:template match="source/@dbURL" xpath-default-namespace="">
      <prop name="databaseURL">{.}</prop>
  </xsl:template>

  <xsl:template match="source/@user" xpath-default-namespace="">
      <prop name="dbUser">{.}</prop>
  </xsl:template>  

  <xsl:template match="source/@driver" xpath-default-namespace="">
      <prop name="DriverClass">{.}</prop>
  </xsl:template>

  <xsl:template match="source/@password" xpath-default-namespace="">
      <encrypted-prop name="dbPassword" encryptionID="base64">{.}</encrypted-prop>
  </xsl:template>

  <xsl:template match="set" xpath-default-namespace="">
      <data-set extensionID="this.is.a.fixed.value" name="{@name}">
          <xsl:apply-templates select="@*, *"/>
      </data-set>
  </xsl:template>

</xsl:stylesheet>

enter image description here