diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala index 452a419aae..04cf009314 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala @@ -253,6 +253,41 @@ class ImportTree( ), ) + /* Conditional types. Proper handling (of static) cases is done elsewhere, this just takes care of the dependencies */ + case TsDeclTypeAlias(cs, _, _, tparams, tpe: TsTypeConditional, codePath) => + val importedCp = importName(codePath) + val importedName = importedCp.parts.last + val importedTparams = tparams.map(typeParam(scope, importName)) + + def warning(explain: String) = + cs ++ Comments( + s"""/** NOTE: Conditional type definitions are impossible to translate to Scala. + | * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + | * $explain. + | * TS definition: {{{ + | ${TsTypeFormatter(tpe)} + | }}} + | */ + |""".stripMargin, + ) + + IArray( + ClassTree( + isImplicit = false, + annotations = IArray(Annotation.JsNative), + level = ProtectionLevel.Public, + name = importedName, + tparams = importedTparams, + parents = Empty, + ctors = Empty, + members = Empty, + classType = ClassType.Trait, + isSealed = false, + comments = warning("You'll have to cast your way around this structure, unfortunately"), + codePath = importedCp, + ), + ) + /* Mapped types. Proper handling (of static) cases is done elsewhere, this just takes care of the dependencies */ case TsDeclTypeAlias( cs, diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala index 0e6888fe15..fa0505660d 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala @@ -256,9 +256,6 @@ class ImportType(stdNames: QualifiedName.StdNames) { case TsTypeThis() => TypeRef.ThisType(NoComments) - case x: TsTypeConditional => - apply(scope, importName)(unify(IArray(x.ifFalse, x.ifTrue))) - case other => val msg = s"Failed type conversion: ${TsTypeFormatter(other)}" scope.logger.info(msg) diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala index df32c100c0..5617e562bd 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala @@ -318,8 +318,7 @@ object Phase1ReadTypescript { if (expandTypeMappings(libName)) T.ExpandTypeMappings.visitTsParsedFile(scope.caching) else identity, // before ExtractInterfaces if (expandTypeMappings(libName)) T.ExpandTypeMappings.After.visitTsParsedFile(scope.caching) else identity, // before ExtractInterfaces ( - T.SimplifyConditionals >> // after ExpandTypeMappings - T.TypeAliasToConstEnum >> + T.TypeAliasToConstEnum >> T.ForwardCtors >> T.ExpandTypeParams >> T.UnionTypesFromKeyOf >> diff --git a/tests/punchcard/check-3/p/punchcard/build.sbt b/tests/punchcard/check-3/p/punchcard/build.sbt index c7cb451223..d584f39918 100644 --- a/tests/punchcard/check-3/p/punchcard/build.sbt +++ b/tests/punchcard/check-3/p/punchcard/build.sbt @@ -1,11 +1,11 @@ organization := "org.scalablytyped" name := "punchcard" -version := "0.0-unknown-ae6eca" +version := "0.0-unknown-591208" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "std" % "0.0-unknown-29cbd9") + "org.scalablytyped" %%% "std" % "0.0-unknown-7dfdbf") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/punchcard/check-3/s/std/build.sbt b/tests/punchcard/check-3/s/std/build.sbt index e92c9f50a6..2d4604619c 100644 --- a/tests/punchcard/check-3/s/std/build.sbt +++ b/tests/punchcard/check-3/s/std/build.sbt @@ -1,6 +1,6 @@ organization := "org.scalablytyped" name := "std" -version := "0.0-unknown-29cbd9" +version := "0.0-unknown-7dfdbf" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( diff --git a/tests/punchcard/check-3/s/std/src/main/scala/typings/std/Extract.scala b/tests/punchcard/check-3/s/std/src/main/scala/typings/std/Extract.scala new file mode 100644 index 0000000000..8d59192029 --- /dev/null +++ b/tests/punchcard/check-3/s/std/src/main/scala/typings/std/Extract.scala @@ -0,0 +1,15 @@ +package typings.std + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends U ? T : never + }}} + */ +@js.native +trait Extract[T, U] extends StObject diff --git a/tests/punchcard/check-3/s/std/src/main/scala/typings/std/package.scala b/tests/punchcard/check-3/s/std/src/main/scala/typings/std/package.scala index 65a76a7368..37bb3fa9c1 100644 --- a/tests/punchcard/check-3/s/std/src/main/scala/typings/std/package.scala +++ b/tests/punchcard/check-3/s/std/src/main/scala/typings/std/package.scala @@ -5,8 +5,6 @@ import scala.scalajs.js import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} -type Extract[T, U] = T - /** NOTE: Mapped type definitions are impossible to translate to Scala. * See https://www.typescriptlang.org/docs/handbook/2/mapped-types.html for an intro. * This translation is imprecise and ignores the effect of the type mapping. diff --git a/tests/react-integration-test/check-japgolly-3/c/componentstest/build.sbt b/tests/react-integration-test/check-japgolly-3/c/componentstest/build.sbt index 6ddaf4c5df..8882bcf934 100644 --- a/tests/react-integration-test/check-japgolly-3/c/componentstest/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/c/componentstest/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "componentstest" -version := "0.0-unknown-192563" +version := "0.0-unknown-c856ab" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react-bootstrap/build.sbt b/tests/react-integration-test/check-japgolly-3/r/react-bootstrap/build.sbt index 2b0a56fa94..6c39ca50a3 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react-bootstrap/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/r/react-bootstrap/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-bootstrap" -version := "0.32-917bae" +version := "0.32-6eac56" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react-contextmenu/build.sbt b/tests/react-integration-test/check-japgolly-3/r/react-contextmenu/build.sbt index 96c56c4ab7..9a4eb59c2d 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react-contextmenu/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/r/react-contextmenu/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-contextmenu" -version := "2.13.0-62c09e" +version := "2.13.0-e70b6a" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react-dropzone/build.sbt b/tests/react-integration-test/check-japgolly-3/r/react-dropzone/build.sbt index 7b78a119b2..503714fc6e 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react-dropzone/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/r/react-dropzone/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-dropzone" -version := "10.1.10-3f6e87" +version := "10.1.10-505392" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react-markdown/build.sbt b/tests/react-integration-test/check-japgolly-3/r/react-markdown/build.sbt index 7b5bc2aee7..f336ef4d5a 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react-markdown/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/r/react-markdown/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-markdown" -version := "0.0-unknown-7ebfca" +version := "0.0-unknown-a12fbc" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react-native/build.sbt b/tests/react-integration-test/check-japgolly-3/r/react-native/build.sbt index 79c41ae0fb..09347207d7 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react-native/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/r/react-native/build.sbt @@ -1,12 +1,12 @@ organization := "org.scalablytyped" name := "react-native" -version := "0.0-unknown-0fb830" +version := "0.0-unknown-0c8e8e" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react-select/build.sbt b/tests/react-integration-test/check-japgolly-3/r/react-select/build.sbt index 7b12c39ce6..b84c214c7b 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react-select/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/r/react-select/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-select" -version := "0.0-unknown-f830c1" +version := "0.0-unknown-685a3b" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react/build.sbt b/tests/react-integration-test/check-japgolly-3/r/react/build.sbt index e7d1bc2c96..71a87c2f82 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/r/react/build.sbt @@ -1,12 +1,12 @@ organization := "org.scalablytyped" name := "react" -version := "16.9.2-1a0f7f" +version := "16.9.2-89c3ae" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/anon.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/anon.scala index 0e30c99db0..1d1a419250 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/anon.scala +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/anon.scala @@ -13,20 +13,20 @@ import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, J object anon { - trait `0` extends StObject { + trait `0`[R] extends StObject { - var ref: js.UndefOr[Exclude[Any, String]] = js.undefined + var ref: js.UndefOr[Exclude[R, String]] = js.undefined } object `0` { - inline def apply(): `0` = { + inline def apply[R](): `0`[R] = { val __obj = js.Dynamic.literal() - __obj.asInstanceOf[`0`] + __obj.asInstanceOf[`0`[R]] } - extension [Self <: `0`](x: Self) { + extension [Self <: `0`[?], R](x: Self & `0`[R]) { - inline def setRef(value: Exclude[Any, String]): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) + inline def setRef(value: Exclude[R, String]): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) inline def setRefUndefined: Self = StObject.set(x, "ref", js.undefined) } diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ComponentProps.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ComponentProps.scala new file mode 100644 index 0000000000..d6c27ff74f --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ComponentProps.scala @@ -0,0 +1,32 @@ +package typingsJapgolly.react.mod + +import typingsJapgolly.react.reactStrings.a_ +import typingsJapgolly.react.reactStrings.abbr +import typingsJapgolly.react.reactStrings.address +import typingsJapgolly.react.reactStrings.area +import typingsJapgolly.react.reactStrings.article +import typingsJapgolly.react.reactStrings.aside +import typingsJapgolly.react.reactStrings.audio +import typingsJapgolly.react.reactStrings.b +import typingsJapgolly.react.reactStrings.base +import typingsJapgolly.react.reactStrings.bdi +import typingsJapgolly.react.reactStrings.bdo +import typingsJapgolly.react.reactStrings.big +import typingsJapgolly.react.reactStrings.view +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded, + * or ComponentPropsWithoutRef when refs are not supported. + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends react.react.JSXElementConstructor ? P : T extends 'a' | 'abbr' | 'address' | 'area' | 'article' | 'aside' | 'audio' | 'b' | 'base' | 'bdi' | 'bdo' | 'big' | 'view' ? react.react..JSX.IntrinsicElements[T] : {} + }}} + */ +@js.native +trait ComponentProps[T /* <: a_ | abbr | address | area | article | aside | audio | b | base | bdi | bdo | big | view | JSXElementConstructor[Any] */] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ComponentPropsWithRef.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ComponentPropsWithRef.scala new file mode 100644 index 0000000000..51c237cc45 --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ComponentPropsWithRef.scala @@ -0,0 +1,15 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends react.react.ComponentClass ? react.react.PropsWithoutRef

& react.react.RefAttributes * / any> : react.react.PropsWithRef> + }}} + */ +@js.native +trait ComponentPropsWithRef[T /* <: japgolly.scalajs.react.facade.React.ElementType */] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ContextType.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ContextType.scala new file mode 100644 index 0000000000..dcff40a644 --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ContextType.scala @@ -0,0 +1,15 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + C extends react.react.Context ? T : never + }}} + */ +@js.native +trait ContextType[C /* <: Context[Any] */] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/Defaultize.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/Defaultize.scala new file mode 100644 index 0000000000..5550d437db --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/Defaultize.scala @@ -0,0 +1,19 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +// Any prop that has a default prop becomes optional, but its type is unchanged +// Undeclared default props are augmented into the resulting allowable attributes +// If declared props have indexed properties, ignore default props entirely as keyof gets widened +// Wrap in an outer-level conditional type to allow distribution over props that are unions +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + P extends any ? string extends keyof P ? P : std.Pick> & std.Partial * / any>> & std.Partial>> : never + }}} + */ +@js.native +trait Defaultize[P, D] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/FunctionComponentElement.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/FunctionComponentElement.scala index 4f430c8cf7..613da67031 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/FunctionComponentElement.scala +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/FunctionComponentElement.scala @@ -8,7 +8,9 @@ trait FunctionComponentElement[P] extends StObject with ReactElement { - var ref: js.UndefOr[Any] = js.undefined + var ref: js.UndefOr[ + /* import warning: importer.ImportType#apply Failed type conversion: 'ref' extends keyof P ? P extends react.anon.Ref ? R : never : never */ js.Any + ] = js.undefined } object FunctionComponentElement { @@ -20,7 +22,9 @@ object FunctionComponentElement { extension [Self <: FunctionComponentElement[?], P](x: Self & FunctionComponentElement[P]) { - inline def setRef(value: Any): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) + inline def setRef( + value: /* import warning: importer.ImportType#apply Failed type conversion: 'ref' extends keyof P ? P extends react.anon.Ref ? R : never : never */ js.Any + ): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) inline def setRefUndefined: Self = StObject.set(x, "ref", js.undefined) } diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/IsExactlyAny.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/IsExactlyAny.scala index 6d185624c9..e68ffa7fe7 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/IsExactlyAny.scala +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/IsExactlyAny.scala @@ -6,8 +6,12 @@ import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, J // naked 'any' type in a conditional type will short circuit and union both the then/else branches // so boolean is only resolved for T = any -/* Rewritten from type alias, can be one of: - - typingsJapgolly.react.reactBooleans.`false` - - typingsJapgolly.react.reactBooleans.`true` -*/ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + boolean extends T extends never ? true : false ? true : false + }}} + */ +@js.native trait IsExactlyAny[T] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/MergePropTypes.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/MergePropTypes.scala new file mode 100644 index 0000000000..f7b394d158 --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/MergePropTypes.scala @@ -0,0 +1,18 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +// Try to resolve ill-defined props like for JS users: props can be any, or sometimes objects with properties of type any +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + // Distribute over P in case it is a union type +P extends any ? react.react.IsExactlyAny

extends true ? T : // If declared props have indexed properties, ignore inferred props entirely as keyof gets widened +string extends keyof P ? P : std.Pick> & std.Pick>> & std.Pick> : never + }}} + */ +@js.native +trait MergePropTypes[P, T] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/PropsWithRef.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/PropsWithRef.scala new file mode 100644 index 0000000000..42c7dfa78a --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/PropsWithRef.scala @@ -0,0 +1,16 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** Ensures that the props do not include string ref, which cannot be forwarded */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + 'ref' extends keyof P ? P extends react.anon.Ref ? string extends R ? react.react.PropsWithoutRef

& react.anon.0 : P : P : P + }}} + */ +@js.native +trait PropsWithRef[P] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/PropsWithoutRef.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/PropsWithoutRef.scala new file mode 100644 index 0000000000..f63a2a5a03 --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/PropsWithoutRef.scala @@ -0,0 +1,16 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** Ensures that the props do not include ref at all */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + 'ref' extends keyof P ? std.Pick> : P + }}} + */ +@js.native +trait PropsWithoutRef[P] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReactChildren.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReactChildren.scala index 1dc9bd0629..0384dd98bd 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReactChildren.scala +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReactChildren.scala @@ -18,7 +18,7 @@ trait ReactChildren extends StObject { def map[T, C](children: C, fn: js.Function2[/* child */ C, /* index */ Double, T]): js.Array[T] = js.native def map[T, C](children: js.Array[C], fn: js.Function2[/* child */ C, /* index */ Double, T]): js.Array[T] = js.native - def only[C](children: C): C = js.native + def only[C](children: C): /* import warning: importer.ImportType#apply Failed type conversion: C extends std.Array ? never : C */ js.Any = js.native def toArray[C](children: C): js.Array[C] = js.native def toArray[C](children: js.Array[C]): js.Array[C] = js.native diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReactManagedAttributes.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReactManagedAttributes.scala new file mode 100644 index 0000000000..b1bb6dceca --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReactManagedAttributes.scala @@ -0,0 +1,15 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + C extends react.anon.DefaultProps ? react.react.Defaultize * / any>, D> : C extends react.anon.PropTypes ? react.react.MergePropTypes * / any> : C extends react.anon.1 ? react.react.Defaultize : P + }}} + */ +@js.native +trait ReactManagedAttributes[C, P] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReducerAction.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReducerAction.scala new file mode 100644 index 0000000000..5504d4c435 --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReducerAction.scala @@ -0,0 +1,15 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + R extends react.react.Reducer ? A : never + }}} + */ +@js.native +trait ReducerAction[R /* <: Reducer[Any, Any] */] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReducerState.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReducerState.scala new file mode 100644 index 0000000000..ba1fca9471 --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/ReducerState.scala @@ -0,0 +1,17 @@ +package typingsJapgolly.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +// types used to try and prevent the compiler from reducing S +// to a supertype common with the second argument to useReducer() +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + R extends react.react.Reducer ? S : never + }}} + */ +@js.native +trait ReducerState[R /* <: Reducer[Any, Any] */] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/global.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/global.scala index e27ff66f4a..9c4a87131c 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/global.scala +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/global.scala @@ -113,6 +113,14 @@ object global { // We can't recurse forever because `type` can't be self-referential; // let's assume it's reasonable to do a single React.lazy() around a single React.memo() / vice-versa - type LibraryManagedAttributes[C, P] = ReactManagedAttributes[Any | C, P] + /** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + C extends react.react.MemoExoticComponent | react.react.LazyExoticComponent ? T extends react.react.MemoExoticComponent | react.react.LazyExoticComponent ? react.react.ReactManagedAttributes : react.react.ReactManagedAttributes : react.react.ReactManagedAttributes + }}} + */ + @js.native + trait LibraryManagedAttributes[C, P] extends StObject } } diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/package.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/package.scala index a9b306b3a8..f1feef6244 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/package.scala +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/mod/package.scala @@ -24,7 +24,6 @@ import org.scalajs.dom.EventTarget import org.scalajs.dom.HTMLElement import org.scalajs.dom.HTMLInputElement import org.scalajs.dom.SVGElement -import typingsJapgolly.react.anon.`0` import typingsJapgolly.react.mod.^ import typingsJapgolly.react.reactStrings.a_ import typingsJapgolly.react.reactStrings.abbr @@ -40,12 +39,10 @@ import typingsJapgolly.react.reactStrings.bdo import typingsJapgolly.react.reactStrings.big import typingsJapgolly.react.reactStrings.input import typingsJapgolly.react.reactStrings.mount -import typingsJapgolly.react.reactStrings.ref import typingsJapgolly.react.reactStrings.update import typingsJapgolly.react.reactStrings.view import typingsJapgolly.std.Exclude import typingsJapgolly.std.Partial -import typingsJapgolly.std.Pick import org.scalablytyped.runtime.StObject import scala.scalajs.js import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} @@ -439,15 +436,6 @@ type ClassicFactory[P] = CFactory[P, ClassicComponent[P, js.Object]] type ClipboardEventHandler[T] = EventHandler[ReactClipboardEventFrom[T & org.scalajs.dom.Element]] -/** - * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded, - * or ComponentPropsWithoutRef when refs are not supported. - */ -type ComponentProps[T /* <: a_ | abbr | address | area | article | aside | audio | b | base | bdi | bdo | big | view | JSXElementConstructor[Any] */] = js.Object | (/* import warning: importer.ImportType#apply Failed type conversion: react.react..JSX.IntrinsicElements[T] */ js.Any) - -type ComponentPropsWithRef[T /* <: japgolly.scalajs.react.facade.React.ElementType */] = PropsWithRef[ComponentProps[T]] | (PropsWithoutRef[Any] & (RefAttributes[ -/* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify InstanceType */ Any])) - type ComponentPropsWithoutRef[T /* <: japgolly.scalajs.react.facade.React.ElementType */] = PropsWithoutRef[ComponentProps[T]] type ComponentState = Any @@ -458,18 +446,6 @@ type CompositionEventHandler[T] = EventHandler[ReactCompositionEventFrom[T & org type Consumer[T] = ExoticComponent[ConsumerProps[T]] -type ContextType[C /* <: Context[Any] */] = Any - -// Any prop that has a default prop becomes optional, but its type is unchanged -// Undeclared default props are augmented into the resulting allowable attributes -// If declared props have indexed properties, ignore default props entirely as keyof gets widened -// Wrap in an outer-level conditional type to allow distribution over props that are unions -type Defaultize[P, D] = ((Pick[P, Exclude[/* keyof P */ String, /* keyof D */ String]]) & (Partial[ -Pick[ - P, - /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify Extract */ Any -]]) & (Partial[Pick[D, Exclude[/* keyof D */ String, /* keyof P */ String]]])) | P - // The identity check is done with the SameValue algorithm (Object.is), which is stricter than === // TODO (TypeScript 3.0): ReadonlyArray type DependencyList = /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify ReadonlyArray */ Any @@ -535,9 +511,6 @@ type KeyboardEventHandler[T] = EventHandler[ReactKeyboardEventFrom[T & org.scala type LegacyRef[T] = String | Ref[T] -// Try to resolve ill-defined props like for JS users: props can be any, or sometimes objects with properties of type any -type MergePropTypes[P, T] = ((Pick[P, NotExactlyAnyPropertyKeys[P]]) & (Pick[T, Exclude[/* keyof T */ String, NotExactlyAnyPropertyKeys[P]]]) & (Pick[P, Exclude[/* keyof P */ String, /* keyof T */ String]])) | P | T - type MouseEventHandler[T] = EventHandler[ReactMouseEventFrom[T & org.scalajs.dom.Element]] type NativeAnimationEvent = org.scalajs.dom.AnimationEvent @@ -583,12 +556,6 @@ Unit] type PropsWithChildren[P] = P & typingsJapgolly.react.anon.Children -/** Ensures that the props do not include string ref, which cannot be forwarded */ -type PropsWithRef[P] = P | (PropsWithoutRef[P] & `0`) - -/** Ensures that the props do not include ref at all */ -type PropsWithoutRef[P] = P | (Pick[P, Exclude[/* keyof P */ String, ref]]) - // NOTE: only the Context object itself can get a displayName // https://github.com/facebook/react-devtools/blob/e0b854e4c/backend/attachRendererFiber.js#L310-L325 type Provider[T] = ProviderExoticComponent[ProviderProps[T]] @@ -610,15 +577,6 @@ type ReactHTMLElement[T /* <: HTMLElement */] = DetailedReactHTMLElement[AllHTML // ---------------------------------------------------------------------- type ReactInstance = (japgolly.scalajs.react.facade.React.Component[Any & js.Object, js.Object]) | org.scalajs.dom.Element -type ReactManagedAttributes[C, P] = P | (Defaultize[ -(MergePropTypes[ - P, - /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify PropTypes.InferProps */ Any -]) | P, -Any]) | (MergePropTypes[ -P, -/* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify PropTypes.InferProps */ Any]) - type ReactNode = js.UndefOr[ReactChild | ReactFragment | ReactPortal | Boolean] // @@ -635,12 +593,6 @@ type ReactType[P] = japgolly.scalajs.react.facade.React.ElementType // Unlike redux, the actions _can_ be anything type Reducer[S, A] = js.Function2[/* prevState */ S, /* action */ A, S] -type ReducerAction[R /* <: Reducer[Any, Any] */] = Any - -// types used to try and prevent the compiler from reducing S -// to a supertype common with the second argument to useReducer() -type ReducerState[R /* <: Reducer[Any, Any] */] = Any - type Ref[T] = (js.Function1[/* instance */ T | Null, Unit]) | RefHandle[T] | Null type Requireable[T] = /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify PropTypes.Requireable */ Any diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/reactBooleans.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/reactBooleans.scala deleted file mode 100644 index 78bad95928..0000000000 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/reactBooleans.scala +++ /dev/null @@ -1,21 +0,0 @@ -package typingsJapgolly.react - -import typingsJapgolly.react.mod.IsExactlyAny -import org.scalablytyped.runtime.StObject -import scala.scalajs.js -import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} - -object reactBooleans { - - @js.native - sealed trait `false` - extends StObject - with IsExactlyAny[Any] - inline def `false`: `false` = false.asInstanceOf[`false`] - - @js.native - sealed trait `true` - extends StObject - with IsExactlyAny[Any] - inline def `true`: `true` = true.asInstanceOf[`true`] -} diff --git a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/reactStrings.scala b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/reactStrings.scala index f3b9b80be1..e6057256f2 100644 --- a/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/reactStrings.scala +++ b/tests/react-integration-test/check-japgolly-3/r/react/src/main/scala/typingsJapgolly/react/reactStrings.scala @@ -758,10 +758,6 @@ object reactStrings { sealed trait rect extends StObject inline def rect: rect = "rect".asInstanceOf[rect] - @js.native - sealed trait ref extends StObject - inline def ref: ref = "ref".asInstanceOf[ref] - @js.native sealed trait removals extends StObject inline def removals: removals = "removals".asInstanceOf[removals] diff --git a/tests/react-integration-test/check-japgolly-3/s/semantic-ui-react/build.sbt b/tests/react-integration-test/check-japgolly-3/s/semantic-ui-react/build.sbt index 3b59603014..4c56e402b3 100644 --- a/tests/react-integration-test/check-japgolly-3/s/semantic-ui-react/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/s/semantic-ui-react/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "semantic-ui-react" -version := "0.0-unknown-133ff5" +version := "0.0-unknown-68bc54" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-event-listener/build.sbt b/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-event-listener/build.sbt index 61a2c5b7a6..2119ff7254 100644 --- a/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-event-listener/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-event-listener/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "stardust-ui__react-component-event-listener" -version := "0.38.0-a2d225" +version := "0.38.0-90ae78" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-ref/build.sbt b/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-ref/build.sbt index ede02034c7..0281d28f59 100644 --- a/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-ref/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/s/stardust-ui__react-component-ref/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "stardust-ui__react-component-ref" -version := "0.38.0-2d4d92" +version := "0.38.0-bb268d" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.github.japgolly.scalajs-react" %%% "core" % "2.1.1", "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "react" % "16.9.2-1a0f7f", - "org.scalablytyped" %%% "std" % "0.0-unknown-57c945") + "org.scalablytyped" %%% "react" % "16.9.2-89c3ae", + "org.scalablytyped" %%% "std" % "0.0-unknown-f06d0f") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-japgolly-3/s/std/build.sbt b/tests/react-integration-test/check-japgolly-3/s/std/build.sbt index b50f0f728c..024c5a2543 100644 --- a/tests/react-integration-test/check-japgolly-3/s/std/build.sbt +++ b/tests/react-integration-test/check-japgolly-3/s/std/build.sbt @@ -1,6 +1,6 @@ organization := "org.scalablytyped" name := "std" -version := "0.0-unknown-57c945" +version := "0.0-unknown-f06d0f" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( diff --git a/tests/react-integration-test/check-japgolly-3/s/std/src/main/scala/typingsJapgolly/std/Exclude.scala b/tests/react-integration-test/check-japgolly-3/s/std/src/main/scala/typingsJapgolly/std/Exclude.scala new file mode 100644 index 0000000000..3d2891da17 --- /dev/null +++ b/tests/react-integration-test/check-japgolly-3/s/std/src/main/scala/typingsJapgolly/std/Exclude.scala @@ -0,0 +1,18 @@ +package typingsJapgolly.std + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * Exclude from T those types that are assignable to U + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends U ? never : T + }}} + */ +@js.native +trait Exclude[T, U] extends StObject diff --git a/tests/react-integration-test/check-japgolly-3/s/std/src/main/scala/typingsJapgolly/std/package.scala b/tests/react-integration-test/check-japgolly-3/s/std/src/main/scala/typingsJapgolly/std/package.scala index a064cfca09..abb809fb52 100644 --- a/tests/react-integration-test/check-japgolly-3/s/std/src/main/scala/typingsJapgolly/std/package.scala +++ b/tests/react-integration-test/check-japgolly-3/s/std/src/main/scala/typingsJapgolly/std/package.scala @@ -14,11 +14,6 @@ type CompositionEvent = org.scalajs.dom.Event type DragEvent = org.scalajs.dom.Event -/** - * Exclude from T those types that are assignable to U - */ -type Exclude[T, U] = T - type FocusEvent = org.scalajs.dom.Event type HTMLAnchorElement = org.scalajs.dom.HTMLElement diff --git a/tests/react-integration-test/check-slinky-3/c/componentstest/build.sbt b/tests/react-integration-test/check-slinky-3/c/componentstest/build.sbt index 84bd22e10c..346acd9241 100644 --- a/tests/react-integration-test/check-slinky-3/c/componentstest/build.sbt +++ b/tests/react-integration-test/check-slinky-3/c/componentstest/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "componentstest" -version := "0.0-unknown-d0f168" +version := "0.0-unknown-b559f4" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react-bootstrap/build.sbt b/tests/react-integration-test/check-slinky-3/r/react-bootstrap/build.sbt index 33885d09a7..dfa7f0e199 100644 --- a/tests/react-integration-test/check-slinky-3/r/react-bootstrap/build.sbt +++ b/tests/react-integration-test/check-slinky-3/r/react-bootstrap/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-bootstrap" -version := "0.32-5991ac" +version := "0.32-9191df" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react-contextmenu/build.sbt b/tests/react-integration-test/check-slinky-3/r/react-contextmenu/build.sbt index a145e143ed..5a9e001015 100644 --- a/tests/react-integration-test/check-slinky-3/r/react-contextmenu/build.sbt +++ b/tests/react-integration-test/check-slinky-3/r/react-contextmenu/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-contextmenu" -version := "2.13.0-a9fee0" +version := "2.13.0-fb96e3" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react-dropzone/build.sbt b/tests/react-integration-test/check-slinky-3/r/react-dropzone/build.sbt index 3927b7a8fd..29bbd09a91 100644 --- a/tests/react-integration-test/check-slinky-3/r/react-dropzone/build.sbt +++ b/tests/react-integration-test/check-slinky-3/r/react-dropzone/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-dropzone" -version := "10.1.10-438eca" +version := "10.1.10-bdd78f" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react-markdown/build.sbt b/tests/react-integration-test/check-slinky-3/r/react-markdown/build.sbt index ed446a6f85..a0a03f0472 100644 --- a/tests/react-integration-test/check-slinky-3/r/react-markdown/build.sbt +++ b/tests/react-integration-test/check-slinky-3/r/react-markdown/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-markdown" -version := "0.0-unknown-7d337f" +version := "0.0-unknown-c5de7a" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react-native/build.sbt b/tests/react-integration-test/check-slinky-3/r/react-native/build.sbt index ec6cac8075..bc45371b9a 100644 --- a/tests/react-integration-test/check-slinky-3/r/react-native/build.sbt +++ b/tests/react-integration-test/check-slinky-3/r/react-native/build.sbt @@ -1,12 +1,12 @@ organization := "org.scalablytyped" name := "react-native" -version := "0.0-unknown-8a9d07" +version := "0.0-unknown-403d93" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react-select/build.sbt b/tests/react-integration-test/check-slinky-3/r/react-select/build.sbt index 1065ec902b..477979b37d 100644 --- a/tests/react-integration-test/check-slinky-3/r/react-select/build.sbt +++ b/tests/react-integration-test/check-slinky-3/r/react-select/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "react-select" -version := "0.0-unknown-630df4" +version := "0.0-unknown-118bbf" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react/build.sbt b/tests/react-integration-test/check-slinky-3/r/react/build.sbt index 5f47cbc90d..131f583a1d 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/build.sbt +++ b/tests/react-integration-test/check-slinky-3/r/react/build.sbt @@ -1,12 +1,12 @@ organization := "org.scalablytyped" name := "react" -version := "16.9.2-3e698f" +version := "16.9.2-2aa5d1" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/anon.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/anon.scala index 4db8579432..4843208a94 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/anon.scala +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/anon.scala @@ -8,20 +8,20 @@ import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, J object anon { - trait `0` extends StObject { + trait `0`[R] extends StObject { - var ref: js.UndefOr[Exclude[Any, String]] = js.undefined + var ref: js.UndefOr[Exclude[R, String]] = js.undefined } object `0` { - inline def apply(): `0` = { + inline def apply[R](): `0`[R] = { val __obj = js.Dynamic.literal() - __obj.asInstanceOf[`0`] + __obj.asInstanceOf[`0`[R]] } - extension [Self <: `0`](x: Self) { + extension [Self <: `0`[?], R](x: Self & `0`[R]) { - inline def setRef(value: Exclude[Any, String]): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) + inline def setRef(value: Exclude[R, String]): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) inline def setRefUndefined: Self = StObject.set(x, "ref", js.undefined) } diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ComponentProps.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ComponentProps.scala new file mode 100644 index 0000000000..6e48938efd --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ComponentProps.scala @@ -0,0 +1,32 @@ +package typingsSlinky.react.mod + +import typingsSlinky.react.reactStrings.a_ +import typingsSlinky.react.reactStrings.abbr +import typingsSlinky.react.reactStrings.address +import typingsSlinky.react.reactStrings.area +import typingsSlinky.react.reactStrings.article +import typingsSlinky.react.reactStrings.aside +import typingsSlinky.react.reactStrings.audio +import typingsSlinky.react.reactStrings.b +import typingsSlinky.react.reactStrings.base +import typingsSlinky.react.reactStrings.bdi +import typingsSlinky.react.reactStrings.bdo +import typingsSlinky.react.reactStrings.big +import typingsSlinky.react.reactStrings.view +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded, + * or ComponentPropsWithoutRef when refs are not supported. + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends react.react.JSXElementConstructor ? P : T extends 'a' | 'abbr' | 'address' | 'area' | 'article' | 'aside' | 'audio' | 'b' | 'base' | 'bdi' | 'bdo' | 'big' | 'view' ? react.react..JSX.IntrinsicElements[T] : {} + }}} + */ +@js.native +trait ComponentProps[T /* <: a_ | abbr | address | area | article | aside | audio | b | base | bdi | bdo | big | view | JSXElementConstructor[Any] */] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ComponentPropsWithRef.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ComponentPropsWithRef.scala new file mode 100644 index 0000000000..aabf6a3669 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ComponentPropsWithRef.scala @@ -0,0 +1,15 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends react.react.ComponentClass ? react.react.PropsWithoutRef

& react.react.RefAttributes * / any> : react.react.PropsWithRef> + }}} + */ +@js.native +trait ComponentPropsWithRef[T /* <: slinky.core.facade.ReactElement */] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ContextType.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ContextType.scala new file mode 100644 index 0000000000..8153ac4d48 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ContextType.scala @@ -0,0 +1,15 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + C extends react.react.Context ? T : never + }}} + */ +@js.native +trait ContextType[C /* <: Context[Any] */] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/Defaultize.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/Defaultize.scala new file mode 100644 index 0000000000..4aec078e33 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/Defaultize.scala @@ -0,0 +1,19 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +// Any prop that has a default prop becomes optional, but its type is unchanged +// Undeclared default props are augmented into the resulting allowable attributes +// If declared props have indexed properties, ignore default props entirely as keyof gets widened +// Wrap in an outer-level conditional type to allow distribution over props that are unions +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + P extends any ? string extends keyof P ? P : std.Pick> & std.Partial * / any>> & std.Partial>> : never + }}} + */ +@js.native +trait Defaultize[P, D] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/FunctionComponentElement.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/FunctionComponentElement.scala index a6173d944c..a07846cc4a 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/FunctionComponentElement.scala +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/FunctionComponentElement.scala @@ -8,7 +8,9 @@ trait FunctionComponentElement[P] extends StObject with ReactElement { - var ref: js.UndefOr[Any] = js.undefined + var ref: js.UndefOr[ + /* import warning: importer.ImportType#apply Failed type conversion: 'ref' extends keyof P ? P extends react.anon.Ref ? R : never : never */ js.Any + ] = js.undefined } object FunctionComponentElement { @@ -20,7 +22,9 @@ object FunctionComponentElement { extension [Self <: FunctionComponentElement[?], P](x: Self & FunctionComponentElement[P]) { - inline def setRef(value: Any): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) + inline def setRef( + value: /* import warning: importer.ImportType#apply Failed type conversion: 'ref' extends keyof P ? P extends react.anon.Ref ? R : never : never */ js.Any + ): Self = StObject.set(x, "ref", value.asInstanceOf[js.Any]) inline def setRefUndefined: Self = StObject.set(x, "ref", js.undefined) } diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/IsExactlyAny.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/IsExactlyAny.scala index c6c0465f69..264f6cf3df 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/IsExactlyAny.scala +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/IsExactlyAny.scala @@ -6,8 +6,12 @@ import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, J // naked 'any' type in a conditional type will short circuit and union both the then/else branches // so boolean is only resolved for T = any -/* Rewritten from type alias, can be one of: - - typingsSlinky.react.reactBooleans.`false` - - typingsSlinky.react.reactBooleans.`true` -*/ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + boolean extends T extends never ? true : false ? true : false + }}} + */ +@js.native trait IsExactlyAny[T] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/MergePropTypes.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/MergePropTypes.scala new file mode 100644 index 0000000000..a0fe375ba7 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/MergePropTypes.scala @@ -0,0 +1,18 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +// Try to resolve ill-defined props like for JS users: props can be any, or sometimes objects with properties of type any +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + // Distribute over P in case it is a union type +P extends any ? react.react.IsExactlyAny

extends true ? T : // If declared props have indexed properties, ignore inferred props entirely as keyof gets widened +string extends keyof P ? P : std.Pick> & std.Pick>> & std.Pick> : never + }}} + */ +@js.native +trait MergePropTypes[P, T] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/PropsWithRef.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/PropsWithRef.scala new file mode 100644 index 0000000000..526db90167 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/PropsWithRef.scala @@ -0,0 +1,16 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** Ensures that the props do not include string ref, which cannot be forwarded */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + 'ref' extends keyof P ? P extends react.anon.Ref ? string extends R ? react.react.PropsWithoutRef

& react.anon.0 : P : P : P + }}} + */ +@js.native +trait PropsWithRef[P] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/PropsWithoutRef.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/PropsWithoutRef.scala new file mode 100644 index 0000000000..148c1c6614 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/PropsWithoutRef.scala @@ -0,0 +1,16 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** Ensures that the props do not include ref at all */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + 'ref' extends keyof P ? std.Pick> : P + }}} + */ +@js.native +trait PropsWithoutRef[P] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReactChildren.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReactChildren.scala index fdafde71d8..6ee32f9323 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReactChildren.scala +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReactChildren.scala @@ -18,7 +18,7 @@ trait ReactChildren extends StObject { def map[T, C](children: C, fn: js.Function2[/* child */ C, /* index */ Double, T]): js.Array[T] = js.native def map[T, C](children: js.Array[C], fn: js.Function2[/* child */ C, /* index */ Double, T]): js.Array[T] = js.native - def only[C](children: C): C = js.native + def only[C](children: C): /* import warning: importer.ImportType#apply Failed type conversion: C extends std.Array ? never : C */ js.Any = js.native def toArray[C](children: C): js.Array[C] = js.native def toArray[C](children: js.Array[C]): js.Array[C] = js.native diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReactManagedAttributes.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReactManagedAttributes.scala new file mode 100644 index 0000000000..7873ccf5c7 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReactManagedAttributes.scala @@ -0,0 +1,15 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + C extends react.anon.DefaultProps ? react.react.Defaultize * / any>, D> : C extends react.anon.PropTypes ? react.react.MergePropTypes * / any> : C extends react.anon.1 ? react.react.Defaultize : P + }}} + */ +@js.native +trait ReactManagedAttributes[C, P] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReducerAction.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReducerAction.scala new file mode 100644 index 0000000000..c499e0608b --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReducerAction.scala @@ -0,0 +1,15 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + R extends react.react.Reducer ? A : never + }}} + */ +@js.native +trait ReducerAction[R /* <: Reducer[Any, Any] */] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReducerState.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReducerState.scala new file mode 100644 index 0000000000..c9aba6a19e --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/ReducerState.scala @@ -0,0 +1,17 @@ +package typingsSlinky.react.mod + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +// types used to try and prevent the compiler from reducing S +// to a supertype common with the second argument to useReducer() +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + R extends react.react.Reducer ? S : never + }}} + */ +@js.native +trait ReducerState[R /* <: Reducer[Any, Any] */] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/global.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/global.scala index c5e1d5cbaa..1ef822a56b 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/global.scala +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/global.scala @@ -113,6 +113,14 @@ object global { // We can't recurse forever because `type` can't be self-referential; // let's assume it's reasonable to do a single React.lazy() around a single React.memo() / vice-versa - type LibraryManagedAttributes[C, P] = ReactManagedAttributes[Any | C, P] + /** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + C extends react.react.MemoExoticComponent | react.react.LazyExoticComponent ? T extends react.react.MemoExoticComponent | react.react.LazyExoticComponent ? react.react.ReactManagedAttributes : react.react.ReactManagedAttributes : react.react.ReactManagedAttributes + }}} + */ + @js.native + trait LibraryManagedAttributes[C, P] extends StObject } } diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/package.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/package.scala index fbf238090c..fd60ef7f4f 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/package.scala +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/mod/package.scala @@ -21,7 +21,6 @@ import slinky.web.SyntheticTouchEvent import slinky.web.SyntheticTransitionEvent import slinky.web.SyntheticUIEvent import slinky.web.SyntheticWheelEvent -import typingsSlinky.react.anon.`0` import typingsSlinky.react.mod.^ import typingsSlinky.react.reactStrings.a_ import typingsSlinky.react.reactStrings.abbr @@ -37,12 +36,10 @@ import typingsSlinky.react.reactStrings.bdo import typingsSlinky.react.reactStrings.big import typingsSlinky.react.reactStrings.input import typingsSlinky.react.reactStrings.mount -import typingsSlinky.react.reactStrings.ref import typingsSlinky.react.reactStrings.update import typingsSlinky.react.reactStrings.view import typingsSlinky.std.Exclude import typingsSlinky.std.Partial -import typingsSlinky.std.Pick import org.scalablytyped.runtime.StObject import scala.scalajs.js import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} @@ -455,15 +452,6 @@ type ClassicFactory[P] = CFactory[P, ReactComponentClass[P]] type ClipboardEventHandler[T] = EventHandler[SyntheticClipboardEvent[T]] -/** - * NOTE: prefer ComponentPropsWithRef, if the ref is forwarded, - * or ComponentPropsWithoutRef when refs are not supported. - */ -type ComponentProps[T /* <: a_ | abbr | address | area | article | aside | audio | b | base | bdi | bdo | big | view | JSXElementConstructor[Any] */] = js.Object | (/* import warning: importer.ImportType#apply Failed type conversion: react.react..JSX.IntrinsicElements[T] */ js.Any) - -type ComponentPropsWithRef[T /* <: slinky.core.facade.ReactElement */] = PropsWithRef[ComponentProps[T]] | (PropsWithoutRef[Any] & (RefAttributes[ -/* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify InstanceType */ Any])) - type ComponentPropsWithoutRef[T /* <: slinky.core.facade.ReactElement */] = PropsWithoutRef[ComponentProps[T]] type ComponentState = Any @@ -474,18 +462,6 @@ type CompositionEventHandler[T] = EventHandler[SyntheticCompositionEvent[T]] type Consumer[T] = ReactComponentClass[ConsumerProps[T]] -type ContextType[C /* <: Context[Any] */] = Any - -// Any prop that has a default prop becomes optional, but its type is unchanged -// Undeclared default props are augmented into the resulting allowable attributes -// If declared props have indexed properties, ignore default props entirely as keyof gets widened -// Wrap in an outer-level conditional type to allow distribution over props that are unions -type Defaultize[P, D] = ((Pick[P, Exclude[/* keyof P */ String, /* keyof D */ String]]) & (Partial[ -Pick[ - P, - /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify Extract */ Any -]]) & (Partial[Pick[D, Exclude[/* keyof D */ String, /* keyof P */ String]]])) | P - // The identity check is done with the SameValue algorithm (Object.is), which is stricter than === // TODO (TypeScript 3.0): ReadonlyArray type DependencyList = /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify ReadonlyArray */ Any @@ -549,9 +525,6 @@ type KeyboardEventHandler[T] = EventHandler[SyntheticKeyboardEvent[T]] type LegacyRef[T] = String | Ref[T] -// Try to resolve ill-defined props like for JS users: props can be any, or sometimes objects with properties of type any -type MergePropTypes[P, T] = ((Pick[P, NotExactlyAnyPropertyKeys[P]]) & (Pick[T, Exclude[/* keyof T */ String, NotExactlyAnyPropertyKeys[P]]]) & (Pick[P, Exclude[/* keyof P */ String, /* keyof T */ String]])) | P | T - type MouseEventHandler[T] = EventHandler[SyntheticMouseEvent[T]] type NativeAnimationEvent = org.scalajs.dom.AnimationEvent @@ -597,12 +570,6 @@ Unit] type PropsWithChildren[P] = P & typingsSlinky.react.anon.Children -/** Ensures that the props do not include string ref, which cannot be forwarded */ -type PropsWithRef[P] = P | (PropsWithoutRef[P] & `0`) - -/** Ensures that the props do not include ref at all */ -type PropsWithoutRef[P] = P | (Pick[P, Exclude[/* keyof P */ String, ref]]) - // NOTE: only the Context object itself can get a displayName // https://github.com/facebook/react-devtools/blob/e0b854e4c/backend/attachRendererFiber.js#L310-L325 type Provider[T] = ReactComponentClass[ProviderProps[T]] @@ -624,15 +591,6 @@ type ReactHTMLElement[T /* <: HTMLElement */] = DetailedReactHTMLElement[AllHTML // ---------------------------------------------------------------------- type ReactInstance = ReactComponentClass[Any] | Element -type ReactManagedAttributes[C, P] = P | (Defaultize[ -(MergePropTypes[ - P, - /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify PropTypes.InferProps */ Any -]) | P, -Any]) | (MergePropTypes[ -P, -/* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify PropTypes.InferProps */ Any]) - type ReactNode = js.UndefOr[ReactChild | ReactFragment | ReactPortal | Boolean] // @@ -649,12 +607,6 @@ type ReactType[P] = slinky.core.facade.ReactElement // Unlike redux, the actions _can_ be anything type Reducer[S, A] = js.Function2[/* prevState */ S, /* action */ A, S] -type ReducerAction[R /* <: Reducer[Any, Any] */] = Any - -// types used to try and prevent the compiler from reducing S -// to a supertype common with the second argument to useReducer() -type ReducerState[R /* <: Reducer[Any, Any] */] = Any - type Ref[T] = (js.Function1[/* instance */ T | Null, Unit]) | ReactRef[T] | Null type Requireable[T] = /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify PropTypes.Requireable */ Any diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/reactBooleans.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/reactBooleans.scala deleted file mode 100644 index 1eea5b2067..0000000000 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/reactBooleans.scala +++ /dev/null @@ -1,21 +0,0 @@ -package typingsSlinky.react - -import typingsSlinky.react.mod.IsExactlyAny -import org.scalablytyped.runtime.StObject -import scala.scalajs.js -import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} - -object reactBooleans { - - @js.native - sealed trait `false` - extends StObject - with IsExactlyAny[Any] - inline def `false`: `false` = false.asInstanceOf[`false`] - - @js.native - sealed trait `true` - extends StObject - with IsExactlyAny[Any] - inline def `true`: `true` = true.asInstanceOf[`true`] -} diff --git a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/reactStrings.scala b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/reactStrings.scala index c8a6c000be..e39056b9e7 100644 --- a/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/reactStrings.scala +++ b/tests/react-integration-test/check-slinky-3/r/react/src/main/scala/typingsSlinky/react/reactStrings.scala @@ -758,10 +758,6 @@ object reactStrings { sealed trait rect extends StObject inline def rect: rect = "rect".asInstanceOf[rect] - @js.native - sealed trait ref extends StObject - inline def ref: ref = "ref".asInstanceOf[ref] - @js.native sealed trait removals extends StObject inline def removals: removals = "removals".asInstanceOf[removals] diff --git a/tests/react-integration-test/check-slinky-3/s/semantic-ui-react/build.sbt b/tests/react-integration-test/check-slinky-3/s/semantic-ui-react/build.sbt index eeafd819c1..1ed1fd2c2c 100644 --- a/tests/react-integration-test/check-slinky-3/s/semantic-ui-react/build.sbt +++ b/tests/react-integration-test/check-slinky-3/s/semantic-ui-react/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "semantic-ui-react" -version := "0.0-unknown-515aef" +version := "0.0-unknown-87454a" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-event-listener/build.sbt b/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-event-listener/build.sbt index 5885660177..5807928927 100644 --- a/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-event-listener/build.sbt +++ b/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-event-listener/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "stardust-ui__react-component-event-listener" -version := "0.38.0-21b8e7" +version := "0.38.0-b5d89a" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-ref/build.sbt b/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-ref/build.sbt index 960b07ee6e..3a86e72c32 100644 --- a/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-ref/build.sbt +++ b/tests/react-integration-test/check-slinky-3/s/stardust-ui__react-component-ref/build.sbt @@ -1,13 +1,13 @@ organization := "org.scalablytyped" name := "stardust-ui__react-component-ref" -version := "0.38.0-0045d3" +version := "0.38.0-171235" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", "me.shadaj" %%% "slinky-web" % "0.7.2", - "org.scalablytyped" %%% "react" % "16.9.2-3e698f", - "org.scalablytyped" %%% "std" % "0.0-unknown-ee0b59") + "org.scalablytyped" %%% "react" % "16.9.2-2aa5d1", + "org.scalablytyped" %%% "std" % "0.0-unknown-8512d2") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/react-integration-test/check-slinky-3/s/std/build.sbt b/tests/react-integration-test/check-slinky-3/s/std/build.sbt index 17afdac61b..00d6b0b83c 100644 --- a/tests/react-integration-test/check-slinky-3/s/std/build.sbt +++ b/tests/react-integration-test/check-slinky-3/s/std/build.sbt @@ -1,6 +1,6 @@ organization := "org.scalablytyped" name := "std" -version := "0.0-unknown-ee0b59" +version := "0.0-unknown-8512d2" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( diff --git a/tests/react-integration-test/check-slinky-3/s/std/src/main/scala/typingsSlinky/std/Exclude.scala b/tests/react-integration-test/check-slinky-3/s/std/src/main/scala/typingsSlinky/std/Exclude.scala new file mode 100644 index 0000000000..c3d7aeee24 --- /dev/null +++ b/tests/react-integration-test/check-slinky-3/s/std/src/main/scala/typingsSlinky/std/Exclude.scala @@ -0,0 +1,18 @@ +package typingsSlinky.std + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * Exclude from T those types that are assignable to U + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends U ? never : T + }}} + */ +@js.native +trait Exclude[T, U] extends StObject diff --git a/tests/react-integration-test/check-slinky-3/s/std/src/main/scala/typingsSlinky/std/package.scala b/tests/react-integration-test/check-slinky-3/s/std/src/main/scala/typingsSlinky/std/package.scala index 91fec73a4f..a96ee24730 100644 --- a/tests/react-integration-test/check-slinky-3/s/std/src/main/scala/typingsSlinky/std/package.scala +++ b/tests/react-integration-test/check-slinky-3/s/std/src/main/scala/typingsSlinky/std/package.scala @@ -14,11 +14,6 @@ type CompositionEvent = org.scalajs.dom.Event type DragEvent = org.scalajs.dom.Event -/** - * Exclude from T those types that are assignable to U - */ -type Exclude[T, U] = T - type FocusEvent = org.scalajs.dom.Event type HTMLAnchorElement = org.scalajs.dom.HTMLElement diff --git a/tests/type-mappings/check-3/s/std/build.sbt b/tests/type-mappings/check-3/s/std/build.sbt index dae790f918..22bb560bb7 100644 --- a/tests/type-mappings/check-3/s/std/build.sbt +++ b/tests/type-mappings/check-3/s/std/build.sbt @@ -1,6 +1,6 @@ organization := "org.scalablytyped" name := "std" -version := "0.0-unknown-93b52a" +version := "0.0-unknown-dac5cc" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( diff --git a/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/Exclude.scala b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/Exclude.scala new file mode 100644 index 0000000000..d6560e48df --- /dev/null +++ b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/Exclude.scala @@ -0,0 +1,18 @@ +package typings.std + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * Exclude from T those types that are assignable to U + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends U ? never : T + }}} + */ +@js.native +trait Exclude[T, U] extends StObject diff --git a/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/Extract.scala b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/Extract.scala new file mode 100644 index 0000000000..a4c391c96f --- /dev/null +++ b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/Extract.scala @@ -0,0 +1,18 @@ +package typings.std + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * Extract from T those types that are assignable to U + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends U ? T : never + }}} + */ +@js.native +trait Extract[T, U] extends StObject diff --git a/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/InstanceType.scala b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/InstanceType.scala new file mode 100644 index 0000000000..098c349084 --- /dev/null +++ b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/InstanceType.scala @@ -0,0 +1,19 @@ +package typings.std + +import org.scalablytyped.runtime.Instantiable1 +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * Obtain the return type of a constructor function type + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends new (args : ...any): infer R ? R : any + }}} + */ +@js.native +trait InstanceType[T /* <: Instantiable1[/* args (repeated) */ Any, Any] */] extends StObject diff --git a/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/NonNullable.scala b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/NonNullable.scala new file mode 100644 index 0000000000..30423e7c2a --- /dev/null +++ b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/NonNullable.scala @@ -0,0 +1,18 @@ +package typings.std + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * Exclude null and undefined from T + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends null | undefined ? never : T + }}} + */ +@js.native +trait NonNullable[T] extends StObject diff --git a/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/ReturnType.scala b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/ReturnType.scala new file mode 100644 index 0000000000..24a1e9920c --- /dev/null +++ b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/ReturnType.scala @@ -0,0 +1,18 @@ +package typings.std + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** + * Obtain the return type of a function type + */ +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends (args : ...any): infer R ? R : any + }}} + */ +@js.native +trait ReturnType[T /* <: js.Function1[/* repeated */ Any, Any] */] extends StObject diff --git a/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/package.scala b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/package.scala index 41d0ff4b0e..7cf2fb7cbe 100644 --- a/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/package.scala +++ b/tests/type-mappings/check-3/s/std/src/main/scala/typings/std/package.scala @@ -1,32 +1,11 @@ package typings.std -import org.scalablytyped.runtime.Instantiable1 import org.scalablytyped.runtime.StringDictionary import org.scalablytyped.runtime.StObject import scala.scalajs.js import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} -/** - * Exclude from T those types that are assignable to U - */ -type Exclude[T, U] = T - -/** - * Extract from T those types that are assignable to U - */ -type Extract[T, U] = T - -/** - * Obtain the return type of a constructor function type - */ -type InstanceType[T /* <: Instantiable1[/* args (repeated) */ Any, Any] */] = Any - -/** - * Exclude null and undefined from T - */ -type NonNullable[T] = T - /** * Make all properties in T optional */ @@ -86,8 +65,3 @@ type Record[K /* <: /* keyof any */ String */, T] = StringDictionary[T] }}} */ type Required[T] = T - -/** - * Obtain the return type of a function type - */ -type ReturnType[T /* <: js.Function1[/* repeated */ Any, Any] */] = Any diff --git a/tests/type-mappings/check-3/t/type-mappings/build.sbt b/tests/type-mappings/check-3/t/type-mappings/build.sbt index f3ddbd9b16..7c6c50237f 100644 --- a/tests/type-mappings/check-3/t/type-mappings/build.sbt +++ b/tests/type-mappings/check-3/t/type-mappings/build.sbt @@ -1,11 +1,11 @@ organization := "org.scalablytyped" name := "type-mappings" -version := "0.0-unknown-a9d57b" +version := "0.0-unknown-ff16b3" scalaVersion := "3.1.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", - "org.scalablytyped" %%% "std" % "0.0-unknown-93b52a") + "org.scalablytyped" %%% "std" % "0.0-unknown-dac5cc") publishArtifact in packageDoc := false scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/type-mappings/check-3/t/type-mappings/src/main/scala/typings/typeMappings/Omit.scala b/tests/type-mappings/check-3/t/type-mappings/src/main/scala/typings/typeMappings/Omit.scala new file mode 100644 index 0000000000..5fcfb8ac40 --- /dev/null +++ b/tests/type-mappings/check-3/t/type-mappings/src/main/scala/typings/typeMappings/Omit.scala @@ -0,0 +1,15 @@ +package typings.typeMappings + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/** NOTE: Conditional type definitions are impossible to translate to Scala. + * See https://www.typescriptlang.org/docs/handbook/2/conditional-types.html for an intro. + * You'll have to cast your way around this structure, unfortunately. + * TS definition: {{{ + T extends any ? std.Pick> : never + }}} + */ +@js.native +trait Omit[T, K /* <: /* keyof any */ String */] extends StObject diff --git a/tests/type-mappings/check-3/t/type-mappings/src/main/scala/typings/typeMappings/package.scala b/tests/type-mappings/check-3/t/type-mappings/src/main/scala/typings/typeMappings/package.scala index 25abc1f44e..0a09b516d8 100644 --- a/tests/type-mappings/check-3/t/type-mappings/src/main/scala/typings/typeMappings/package.scala +++ b/tests/type-mappings/check-3/t/type-mappings/src/main/scala/typings/typeMappings/package.scala @@ -1,7 +1,6 @@ package typings.typeMappings import org.scalablytyped.runtime.Instantiable0 -import typings.std.Exclude import typings.std.InstanceType import typings.std.NonNullable import typings.std.Partial @@ -24,8 +23,6 @@ type NewedPerson = InstanceType[Instantiable0[Person]] type NonNullablePerson = NonNullable[Person] -type Omit[T, K /* <: /* keyof any */ String */] = Pick[T, Exclude[/* keyof T */ String, K]] - type ReturnedPerson = ReturnType[js.Function0[Person]] type T = Pick[Name | Age, name & age] diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SimplifyConditionals.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SimplifyConditionals.scala deleted file mode 100644 index c7ac16a53f..0000000000 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SimplifyConditionals.scala +++ /dev/null @@ -1,36 +0,0 @@ -package org.scalablytyped.converter.internal -package ts -package transforms - -/** - * Rudimentary support for conditional types - */ -object SimplifyConditionals extends TreeTransformationScopedChanges { - override def leaveTsType(scope: TsTreeScope)(x: TsType): TsType = - x match { - case x: TsTypeConditional => inferAny(x) - case other => other - } - - def inferAny(x: TsTypeConditional): TsType = { - /* It's common to nest these things, so handle that */ - def go(x: TsType): TsType = - x match { - case xx: TsTypeConditional => - lazy val inferredNames: IArray[TsIdent] = - TsTreeTraverse.collect(xx.pred) { case TsTypeInfer(tp) => tp.name } - - lazy val inferAny: TsType => TsType = { - val rewrites: Map[TsType, TsType] = - inferredNames.map(ident => TsTypeRef(ident) -> TsTypeRef.any).toMap - - new ts.transforms.TypeRewriter(x).visitTsType(rewrites) - } - TsTypeConditional(xx.pred, go(inferAny(xx.ifTrue)), go(inferAny(xx.ifFalse))) - - case other => other - } - - go(x) - } -}