-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
2,570 additions
and
899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
"@fluidframework/merge-tree": minor | ||
"@fluidframework/tree": minor | ||
"fluid-framework": minor | ||
--- | ||
--- | ||
"section": fix | ||
--- | ||
|
||
Fix compiler errors when building with libCheck | ||
|
||
Compiling code using Fluid Framework when using TypeScript's `libCheck` (meaning without [skipLibCheck](https://www.typescriptlang.org/tsconfig/#skipLibCheck)), two compile errors can be encountered: | ||
|
||
``` | ||
> tsc | ||
node_modules/@fluidframework/merge-tree/lib/client.d.ts:124:18 - error TS2368: Type parameter name cannot be 'undefined'. | ||
124 walkSegments<undefined>(handler: ISegmentAction<undefined>, start?: number, end?: number, accum?: undefined, splitRange?: boolean): void; | ||
~~~~~~~~~ | ||
node_modules/@fluidframework/tree/lib/util/utils.d.ts:5:29 - error TS7016: Could not find a declaration file for module '@ungap/structured-clone'. 'node_modules/@ungap/structured-clone/esm/index.js' implicitly has an 'any' type. | ||
Try `npm i --save-dev @types/ungap__structured-clone` if it exists or add a new declaration (.d.ts) file containing `declare module '@ungap/structured-clone';` | ||
5 import structuredClone from "@ungap/structured-clone"; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
``` | ||
|
||
The first error impacts projects using TypeScript 5.5 or greater and either of the `fluid-framework` or `@fluidframework/merge-tree` packages. | ||
The second error impacts projects using the `noImplicitAny` tsconfig setting and the `fluid-framework` or `@fluidframework/tree` packages. | ||
|
||
Both have been fixed. | ||
|
||
This should allow `libCheck` to be reenabled in any impacted projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
"fluid-framework": minor | ||
"@fluidframework/tree": minor | ||
--- | ||
--- | ||
"section": tree | ||
--- | ||
|
||
Add `.schema` member to alpha enum schema APIs | ||
|
||
The return value from `@alpha` APIs `enumFromStrings` and `adaptEnum` now has a property named `schema` which can be used to include it in a parent schema. | ||
This replaces the use of `typedObjectValues` which has been removed. | ||
|
||
Use of these APIs now look like: | ||
|
||
```typescript | ||
const schemaFactory = new SchemaFactory("com.myApp"); | ||
const Mode = enumFromStrings(schemaFactory, ["Fun", "Cool"]); | ||
type Mode = NodeFromSchema<(typeof Mode.schema)[number]>; | ||
class Parent extends schemaFactory.object("Parent", { mode: Mode.schema }) {} | ||
``` | ||
|
||
|
||
Previously the last two lines would have been: | ||
|
||
```typescript | ||
type Mode = NodeFromSchema<(typeof Mode)[keyof typeof Mode]>; // This no longer works | ||
class Parent extends schemaFactory.object("Parent", { mode: typedObjectValues(Mode) }) {} // This no longer works | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
"fluid-framework": minor | ||
"@fluidframework/tree": minor | ||
--- | ||
--- | ||
"section": tree | ||
--- | ||
|
||
Improve strictness of input tree types when non-exact schema are provided | ||
|
||
Consider the following code where the type of the schema is not exactly specified: | ||
|
||
```typescript | ||
const schemaFactory = new SchemaFactory("com.myApp"); | ||
class A extends schemaFactory.object("A", {}) {} | ||
class B extends schemaFactory.array("B", schemaFactory.number) {} | ||
|
||
// Gives imprecise type (typeof A | typeof B)[]. The desired precise type here is [typeof A, typeof B]. | ||
const schema = [A, B]; | ||
|
||
const config = new TreeViewConfiguration({ schema }); | ||
const view = sharedTree.viewWith(config); | ||
|
||
// Does not compile since setter for root is typed `never` due to imprecise schema. | ||
view.root = []; | ||
``` | ||
|
||
The assignment of `view.root` is disallowed since a schema with type `(typeof A | typeof B)[]` could be any of: | ||
|
||
```typescript | ||
const schema: (typeof A | typeof B)[] = [A]; | ||
``` | ||
|
||
```typescript | ||
const schema: (typeof A | typeof B)[] = [B]; | ||
``` | ||
|
||
```typescript | ||
const schema: (typeof A | typeof B)[] = [A, B]; | ||
``` | ||
|
||
The attempted assignment is not compatible with all of these (specifically it is incompatible with the first one) so performing this assignment could make the tree out of schema and is thus disallowed. | ||
|
||
To avoid this ambiguity and capture the precise type of `[typeof A, typeof B]`, use one of the following patterns: | ||
|
||
```typescript | ||
const schema = [A, B] as const; | ||
const config = new TreeViewConfiguration({ schema }); | ||
``` | ||
|
||
```typescript | ||
const config = new TreeViewConfiguration({ schema: [A, B] }); | ||
``` | ||
|
||
To help update existing code which accidentally depended on this bug, an `@alpha` API `unsafeArrayToTuple` has been added. | ||
Many usages of this API will produce incorrectly typed outputs. | ||
However, when given `AllowedTypes` arrays which should not contain any unions, but that were accidentally flattened to a single union, it can fix them: | ||
|
||
```typescript | ||
// Gives imprecise type (typeof A | typeof B)[] | ||
const schemaBad = [A, B]; | ||
// Fixes the type to be [typeof A, typeof B] | ||
const schema = unsafeArrayToTuple(schemaBad); | ||
|
||
const config = new TreeViewConfiguration({ schema }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.