Feature: valueof for string, numeric and boolean literals#1877
Feature: valueof for string, numeric and boolean literals#1877timotheeguerin merged 28 commits intomicrosoft:mainfrom
valueof for string, numeric and boolean literals#1877Conversation
|
Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status): Website: https://cadlwebsite.z1.web.core.windows.net/prs/1877/ |
| args: DecoratorArgument[], | ||
| decoratorNode: Node | ||
| ): boolean { | ||
| ): [boolean, DecoratorArgument[]] { |
There was a problem hiding this comment.
@timotheeguerin We have a test failed (ci link) with below error, could you take a look?
Here is our test case link, we have a usage for @extension("x-ms-skip-url-encoding", true).
TypeError: key.startsWith is not a function
at isOpenAPIExtensionKey (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+openapi@0.44.0_5dsz42v7r7ljwzbfu2zuum3liq/node_modules/@typespec/openapi/src/decorators.ts:75:14)
at $extension (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+openapi@0.44.0_5dsz42v7r7ljwzbfu2zuum3liq/node_modules/@typespec/openapi/src/decorators.ts:42:8)
at applyDecoratorToType (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:5480:5)
at finishTypeForProgramAndChecker (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:5456:7)
at finishType (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:3705:12)
at checkModelProperty (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:2993:7)
at checkModelProperties (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:2481:25)
at checkModelStatement (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:2393:5)
at checkModel (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:2324:14)
at getTypeForNode (file:///home/vsts/work/1/s/common/temp/node_modules/.pnpm/@typespec+compiler@0.45.0-dev.26/node_modules/@typespec/compiler/core/checker.ts:615:16)
Error: TypeSpec compiler v0.44.0
There was a problem hiding this comment.
Are you using all the latest dev version or stable version?
There was a problem hiding this comment.
This happens in our nightly build which always refer the latest dev to check any breaking.
There was a problem hiding this comment.
Do you have @typespec/openapi as an explicit dependency in your package.json? I think it it is not the tool will not bump it and due to how npm resolve things it will not use the dev version.
We just released the stable versions, if you can repro with 0.45.0(core) and 0.31.0(azure) then it is probably an issue but from the error I am pretty sure it is a mismatch of deps
There was a problem hiding this comment.
I can't repro with your spec in the playground
There was a problem hiding this comment.
Thanks for the info! Let me deep dive if any dependency mismatch.
fix #1745 Add support for
valueofWaiting on:
Azure PR Azure/typespec-azure#3061
Deprecation
Typespec
Decorators have updated to use
valueoffor their types when expecting a string, numeric or boolean value.If using the decorator directly this is NOT breaking and will continue to work as expected.
If using the decorator via a template parameter the template constraint will need to be updated from
stringtovalueof string(Similar for numeric and boolean types)The old way is still ok but will emit a deprecation warning.
Breaking change
Decorator API
Part of adding
valueofis making the auto conversion of Typespec types more consistent.A decorator that is not specifying a
valueoftype for its parameter will be receiving the exact type. To get the converted string, number or booleanvalueofmust be usedstringstringStringLiteral | Scalarint32numberNumericLiteral | Scalarint8numberNumericLiteral | Scalarfloat32numberNumericLiteral | ScalarbooleanbooleanBooleanLiteral | ScalarbooleanbooleanBooleanLiteral | Scalarvalueof stringstringvalueof int32numbervalueof float64numbervalueof booleanbooleanExample migration
Example mapping
extern dectotypescript signature