Skip to content

Commit

Permalink
Revert "Add satisfies type assertion for typescript (facebook#4797)"
Browse files Browse the repository at this point in the history
This reverts commit 575f206.
  • Loading branch information
Drew Atkinson committed Feb 3, 2025
1 parent 203d8b1 commit 2d52aa9
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type User { name: String }
==================================== OUTPUT ===================================
//- __generated__/barFragment.graphql.ts
/**
* <auto-generated> SignedSource<<0f778584db7b20b3491a3ed42c61cdc1>>
* <auto-generated> SignedSource<<f592d795251b0c88f6e5456bd47a8d10>>
* @lightSyntaxTransform
* @nogrep
*/
Expand All @@ -34,9 +34,6 @@ type User { name: String }
import { ReaderFragment } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
import { foo as userFooResolverType } from "../foo";
// Type assertion validating that `userFooResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(userFooResolverType satisfies () => unknown | null | undefined);
export type barFragment$data = {
readonly foo: ReturnType<typeof userFooResolverType> | null | undefined;
readonly " $fragmentType": "barFragment";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type User { name: String }
==================================== OUTPUT ===================================
//- __generated__/barFragment.graphql.ts
/**
* <auto-generated> SignedSource<<7c2c6939d2e5610ed47a154e9cab2dfd>>
* <auto-generated> SignedSource<<5dff27df4f02d14a44779d79d3f98fbb>>
* @lightSyntaxTransform
* @nogrep
*/
Expand All @@ -35,15 +35,9 @@ type User { name: String }
// @ts-nocheck

import { ReaderFragment } from 'relay-runtime';
import { LiveState, FragmentRefs } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
import { foo as userFooResolverType } from "../foo";
import { ITestResolverContextType } from "@test/package";
// Type assertion validating that `userFooResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(userFooResolverType satisfies (
args: undefined,
context: ITestResolverContextType,
) => LiveState<unknown | null | undefined>);
export type barFragment$data = {
readonly foo: ReturnType<ReturnType<typeof userFooResolverType>["read"]> | null | undefined;
readonly " $fragmentType": "barFragment";
Expand Down
47 changes: 5 additions & 42 deletions compiler/crates/relay-typegen/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use intern::intern;
use itertools::Itertools;
use relay_config::TypegenConfig;

use crate::writer::FunctionTypeAssertion;
use crate::writer::KeyValuePairProp;
use crate::writer::Prop;
use crate::writer::SortedASTList;
use crate::writer::SortedStringKeyList;
Expand Down Expand Up @@ -79,11 +77,11 @@ impl Writer for TypeScriptPrinter {
AST::ReturnTypeOfMethodCall(object, method_name) => {
self.write_return_type_of_method_call(object, *method_name)
}
AST::AssertFunctionType(FunctionTypeAssertion {
function_name,
arguments,
return_type,
}) => self.write_assert_function_type(*function_name, arguments, return_type),
AST::AssertFunctionType(_) => {
// TODO: Add proper support for Resolver type generation in
// typescript: https://github.com/facebook/relay/issues/4772
Ok(())
}
AST::GenericType { outer, inner } => self.write_generic_type(*outer, inner),
AST::PropertyType {
type_,
Expand Down Expand Up @@ -366,41 +364,6 @@ impl TypeScriptPrinter {
}
write!(&mut self.result, ">")
}

fn write_assert_function_type(
&mut self,
function_name: StringKey,
arguments: &[KeyValuePairProp],
return_type: &AST,
) -> FmtResult {
writeln!(
&mut self.result,
"// Type assertion validating that `{}` resolver is correctly implemented.",
function_name
)?;
writeln!(
&mut self.result,
"// A type error here indicates that the type signature of the resolver module is incorrect."
)?;
if arguments.is_empty() {
write!(&mut self.result, "({} satisfies (", function_name)?;
} else {
writeln!(&mut self.result, "({} satisfies (", function_name)?;
self.indentation += 1;
for argument in arguments.iter() {
self.write_indentation()?;
write!(&mut self.result, "{}: ", argument.key)?;
self.write(&argument.value)?;
writeln!(&mut self.result, ",")?;
}
self.indentation -= 1;
}
write!(&mut self.result, ") => ")?;
self.write(return_type)?;
writeln!(&mut self.result, ");")?;

Ok(())
}
}

#[cfg(test)]
Expand Down
8 changes: 7 additions & 1 deletion compiler/crates/relay-typegen/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ fn generate_resolver_type(

let ast = transform_type_reference_into_ast(&schema_field_type, |_| inner_ast);

let return_type = if resolver_metadata.live {
let return_type = if matches!(
typegen_context.project_config.typegen_config.language,
TypegenLanguage::TypeScript
) {
// TODO: Add proper support for Resolver type generation in typescript: https://github.com/facebook/relay/issues/4772
AST::Any
} else if resolver_metadata.live {
runtime_imports.resolver_live_state_type = true;
AST::GenericType {
outer: *LIVE_STATE_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ export type User__pop_star_name$normalization = {
-------------------------------------------------------------------------------
import type { FragmentRefs } from "relay-runtime";
import userPopStarNameResolverType from "PopStarNameResolver";
// Type assertion validating that `userPopStarNameResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(userPopStarNameResolverType satisfies (
rootKey: PopStarNameResolverFragment_name$key,
) => User__pop_star_name$normalization | null | undefined);
export type Foo_user$data = {
readonly poppy: {
readonly name: string | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ export type User__pop_star_name$normalization = {
-------------------------------------------------------------------------------
import type { FragmentRefs } from "relay-runtime";
import userPopStarNameResolverType from "PopStarNameResolver";
// Type assertion validating that `userPopStarNameResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(userPopStarNameResolverType satisfies (
rootKey: PopStarNameResolverFragment_name$key,
) => User__pop_star_name$normalization | null | undefined);
export type Foo_user$data = {
readonly poppy: {
readonly name: string | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ extend type User {
==================================== OUTPUT ===================================
import { FragmentRefs } from "relay-runtime";
import userPopStarNameResolverType from "PopStarNameResolver";
// Type assertion validating that `userPopStarNameResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(userPopStarNameResolverType satisfies (
rootKey: PopStarNameResolverFragment_name$key,
) => unknown | null | undefined);
export type Foo_user$data = {
readonly poppy: NonNullable<ReturnType<typeof userPopStarNameResolverType>>;
readonly " $fragmentType": "Foo_user";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ extend type User {
==================================== OUTPUT ===================================
import { FragmentRefs } from "relay-runtime";
import userPopStarNameResolverType from "PopStarNameResolver";
// Type assertion validating that `userPopStarNameResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(userPopStarNameResolverType satisfies (
rootKey: PopStarNameResolverFragment_name$key,
) => unknown | null | undefined);
export type Foo_user$data = {
readonly poppy: ReturnType<typeof userPopStarNameResolverType> | null | undefined;
readonly " $fragmentType": "Foo_user";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export type ClientEdgeQuery_MyFragment_best_friend = {
-------------------------------------------------------------------------------
import { FragmentRefs, DataID } from "relay-runtime";
import clientUserBestFriendResolverType from "bar";
// Type assertion validating that `clientUserBestFriendResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(clientUserBestFriendResolverType satisfies () => {
readonly id: DataID;
});
export type MyFragment$data = {
readonly best_friend: {
readonly name: string | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export type ClientUser__blob$normalization = {
-------------------------------------------------------------------------------
import { FragmentRefs } from "relay-runtime";
import clientUserBlobResolverType from "bar";
// Type assertion validating that `clientUserBlobResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(clientUserBlobResolverType satisfies () => ClientUser__blob$normalization);
export type MyFragment$data = {
readonly blob: {
readonly data: string | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ type ClientUser {
==================================== OUTPUT ===================================
import { FragmentRefs } from "relay-runtime";
import clientUserNameResolverType from "bar";
// Type assertion validating that `clientUserNameResolverType` resolver is correctly implemented.
// A type error here indicates that the type signature of the resolver module is incorrect.
(clientUserNameResolverType satisfies () => unknown);
export type MyFragment$data = {
readonly name: NonNullable<ReturnType<typeof clientUserNameResolverType>>;
readonly " $fragmentType": "MyFragment";
Expand Down

0 comments on commit 2d52aa9

Please sign in to comment.